import paramiko import sys def run_ssh_command(host, user, password, local_path, remote_path, command): client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: print("Connecting...") client.connect(hostname=host, username=user, password=password, timeout=10) print("Uploading file...") sftp = client.open_sftp() sftp.put(local_path, remote_path) sftp.close() print("Executing command...") stdin, stdout, stderr = client.exec_command(command) exit_status = stdout.channel.recv_exit_status() out = stdout.read().decode() err = stderr.read().decode() if out: print(out) if err: print(err, file=sys.stderr) sys.exit(exit_status) except Exception as e: print(f"Error: {e}", file=sys.stderr) sys.exit(1) finally: client.close() if __name__ == "__main__": host = "161.97.93.156" user = "carlos" password = "Innova1978+*?" local_path = "/tmp/alter_system_only.sql" remote_path = "/tmp/alter_system_only.sql" cmd = "docker exec -i appwrite-mariadb-sss6crntvrcs54qbhvhy5728 mysql -f -u sYoHWwl0DGvEyt3s -psn9YkZqoLV06CQxAy2qsKi36S7POVShT appwrite < /tmp/alter_system_only.sql" run_ssh_command(host, user, password, local_path, remote_path, cmd)