1

Not sure why this is not working, I am attempting to upload an entire directory from my local drive to the sftp but instead of uploading the folder it creates a file that looks like this ".\20200131\doc1.txt"? I have been at this for hours I think I am missing something

def upload_files_to_sftp():
    localpath = r"c:\test\" 
    remotepath = "/uploads/test_Unzipped"
    for root,dirs,_ in os.walk(r"c:\test"):
        for d in dirs:
            folders_to_upload = (os.path.join(root,d))
            print(folders_to_upload)
            with pysftp.Connection('mysftp', username='username', password='mypassword') as sftp:
                sftp.put_r(localpath , remotepath)
Jgm
  • 21
  • 4

1 Answers1

0

Usually an sftp server will also grant ssh access.

If you have ssh access, you could:

(cd /source/dir && tar --create --sparse --one-file-system .) | ssh example.com 'cd /target/dir && tar xfp -'

...using cygwin tar and ssh, for example. IOW, this can easily be reduced to a one-liner in shell.

dstromberg
  • 6,954
  • 1
  • 26
  • 27