【问题标题】:Move files from local to remote server using sftp in python在 python 中使用 sftp 将文件从本地服务器移动到远程服务器
【发布时间】:2018-10-01 10:20:03
【问题描述】:

我想将所有文件从本地目录复制到远程目录。我为此使用了pysftp 库。我下面的代码没有显示任何错误,但我的本地文件也没有被传输到我的远程服务器。

我的代码:

import pysftp
remotepath = '/home/a7user/sftp/sftp/CentralData/'
localpath = 'E:\\backup\\'
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None

with pysftp.Connection(host='xx.xxx.xx.xx',username='user',password='5fTPt00',cnopts=cnopts) as sftp:

 sftp.put_d(localpath,remotepath)
 print('Upload finished')

我做错了什么?

【问题讨论】:

  • 从外观上看,登录 pysftp 并不容易。假设 put_d 是正确的方法(它不是递归的 - 那是 put_r),我认为您最好的选择是编辑 pysftp 的本地副本,以将打印语句添加到 walktree() 和 put_d() 以查看它在做什么。可能还值得检查您是否可以使用 cd 和 put 传输单个文件。
  • 您可以在创建连接时添加 log=1 并将日志的输出添加到您的问题中吗?使用 pysftp.Connection(host='xx.xxx.xx.xx',username='user',password='5fTPt00',cnopts=cnopts, log=1) 作为 sftp:stackoverflow.com/questions/29128205/…

标签: python sftp pysftp


【解决方案1】:

您真正想要使用的可能是put_r() 而不是put_d()?

【讨论】:

  • 感谢@LieRyan put_r( ) 为我工作,实际问题是最新版本。当我在 3.5 版本中测试时,我的版本是 3.7,它运行良好。
猜你喜欢
  • 1970-01-01
  • 2014-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-20
  • 2020-04-24
相关资源
最近更新 更多