Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import sys, paramiko
  2.  
  3. if len(sys.argv) < 3:
  4. print "usage: SFTP_test.py server_address local_file_to_upload"
  5.  
  6. server_address = sys.argv[1]
  7. source_file = sys.argv[2]
  8.  
  9. dest_file = source_file
  10. username = 'student'
  11. password = 'student'
  12. port = 22
  13.  
  14. # create a Transport object with the IP address of the server and the port (Port 22 for SSH)
  15. t = paramiko.Transport((server_address, port))
  16. # connect to the server with the username student and password student
  17. t.connect(username=username, password=password)
  18. # create an SFTP client from the Transport socket object
  19. sftp = paramiko.SFTPClient.from_transport(t)
  20. # upload the source file and call it the name stored in dest_file on the server
  21. sftp.put(source_file, dest_file)
  22. # close the socket/connection
  23. t.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement