Skip to content

Instantly share code, notes, and snippets.

@Ap0dexMe0
Created July 4, 2026 18:19
Show Gist options
  • Select an option

  • Save Ap0dexMe0/1d93914392c8c08fd2adeb50731e3b7b to your computer and use it in GitHub Desktop.

Select an option

Save Ap0dexMe0/1d93914392c8c08fd2adeb50731e3b7b to your computer and use it in GitHub Desktop.
Remote SSH Manager (Upload/Download)
import os
import paramiko
HOST = ""
PORT = 22
USERNAME = ""
PASSWORD = ""
def upload(local_path, remote_path):
if remote_path.endswith("/"):
remote_path = remote_path + os.path.basename(local_path)
with paramiko.Transport((HOST, PORT)) as transport:
transport.connect(username=USERNAME, password=PASSWORD)
with paramiko.SFTPClient.from_transport(transport) as sftp:
sftp.put(local_path, remote_path)
print(f"Uploaded {local_path} -> {remote_path}")
def download(remote_path, local_path):
if os.path.isdir(local_path):
local_path = os.path.join(local_path, os.path.basename(remote_path))
with paramiko.Transport((HOST, PORT)) as transport:
transport.connect(username=USERNAME, password=PASSWORD)
with paramiko.SFTPClient.from_transport(transport) as sftp:
sftp.get(remote_path, local_path)
print(f"Downloaded {remote_path} -> {local_path}")
if __name__ == "__main__":
import sys
if len(sys.argv) < 3:
print("Usage:")
print(" Upload: python ssh_file_transfer.py --upload <local> <remote>")
print(" Download: python ssh_file_transfer.py --download <remote> <local>")
sys.exit(1)
action = sys.argv[1]
if action == "--upload":
upload(sys.argv[2], sys.argv[3])
elif action == "--download":
download(sys.argv[2], sys.argv[3])
else:
print("Unknown action. Use '--upload' or '--download'.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment