Upload file via sftp with python

前端 未结 2 1344
误落风尘
误落风尘 2020-12-14 10:26

I wrote a simple code to upload a file to a sftp server in python. I am using python 2.7

import pysftp

srv = pysftp.Connection(host=\"www.destination.com\",         


        
2条回答
  •  萌比男神i
    2020-12-14 11:14

    import pysftp
    
    with pysftp.Connection(host="www.destination.com", username="root",
    password="password",log="./temp/pysftp.log") as sftp:
    
      srv.cwd('/root/public'): #Write the whole path
      srv.put('C:\Users\XXX\Dropbox\test.txt') #upload file to nodejs/
    

    No srv.close() as connection closed automatically at the end of the with-block

    I did a minor change with cd to cwd

    Syntax -

    # sftp.put('/my/local/filename')  # upload file to public/ on remote
    # sftp.get('remote_file')         # get a remote file
    

提交回复
热议问题