Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import sys
- import traceback
- import paramiko
- # setup logging
- paramiko.util.log_to_file('ftp.log')
- # SFTP configuration
- hostname = 'demo.wftpserver.com'
- port = 2222
- username = 'demo-user'
- password = 'demo-user'
- # Files configuration
- src_file = 'C:/Home/_Oleg/projects/sftp-ku/research.py'
- sftp_base_dir = 'upload/'
- out_file_name = 'research4.py'
- try:
- t = paramiko.Transport((hostname, port))
- t.connect(None, username, password, gss_host=socket.getfqdn(hostname))
- sftp = paramiko.SFTPClient.from_transport(t)
- dirlist = sftp.listdir('.')
- print("Dirlist: %s" % dirlist)
- sftp.put(src_file, '{}{}'.format(sftp_base_dir, out_file_name))
- t.close()
- except Exception as e:
- print('*** Caught exception: %s: %s' % (e.__class__, e))
- traceback.print_exc()
- try:
- t.close()
- except:
- pass
- sys.exit(1)
Add Comment
Please, Sign In to add comment