Last active
June 4, 2023 15:28
-
-
Save zillion45/be2e110587fddb9770fc076325c896f7 to your computer and use it in GitHub Desktop.
paramiko sftp example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import getpass | |
import sys | |
import paramiko | |
LOCAL= '' | |
REMOTE = '' | |
def copy_file(host, port, username, password, src, dest): | |
client = paramiko.SSHClient() | |
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
t = paramiko.Transport((host, port)) | |
t.connect(username=username, password=password) | |
sftp = paramiko.SFTPClient.from_transport(t) | |
print "Copying file %s to %s" % (src, dest) | |
sftp.put(src, dest) | |
sftp.close() | |
t.close() | |
if __name__ == '__main__': | |
username = raw_input("Enter the username: ") | |
password = getpass.getpass("Enter the password: ") | |
if len(sys.argv) > 1: | |
host = sys.argv[1] | |
else: | |
host = raw_input("Enter the hostname: ") | |
port = 22 | |
src = LOCAL | |
dest = REMOTE | |
copy_file(host, port, username, password, src, dest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment