无法使用pysftp将文件夹上传到Sftp
Can't upload folder to Sftp using pysftp
不确定为什么这不起作用,我试图将整个目录从我的本地驱动器上传到 sftp,但它没有上传文件夹,而是创建了一个类似于“.200131\doc1 的文件。文本文件”?我已经在这里工作了几个小时,我想我错过了一些东西
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)
通常 sftp 服务器也会授予 ssh 访问权限。
如果您有 ssh 访问权限,您可以:
(cd /source/dir && tar --create --sparse --one-file-system .) | ssh example.com 'cd /target/dir && tar xfp -'
...例如,使用 cygwin tar 和 ssh。 IOW,这可以很容易地减少到 shell.
中的一行
不确定为什么这不起作用,我试图将整个目录从我的本地驱动器上传到 sftp,但它没有上传文件夹,而是创建了一个类似于“.200131\doc1 的文件。文本文件”?我已经在这里工作了几个小时,我想我错过了一些东西
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)
通常 sftp 服务器也会授予 ssh 访问权限。
如果您有 ssh 访问权限,您可以:
(cd /source/dir && tar --create --sparse --one-file-system .) | ssh example.com 'cd /target/dir && tar xfp -'
...例如,使用 cygwin tar 和 ssh。 IOW,这可以很容易地减少到 shell.
中的一行