提问者:小点点

使用paramiko将目录从一台服务器移动到另一台服务器的Python代码?[副本]


我写了一个python程序,我想移动一个目录和它的文件到另一个服务器我的代码如下

import paramiko

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

client.connect('ipaddr', username='username',password='password')
print ("copying")
sftp = client.open_sftp()
sftp.put('/home/source/workspace/vddir', '/home/destination/workspace/vddir')
sftp.close()

但它显示了这样的错误

Traceback (most recent call last):
  File "pycode.py", line 9, in <module>
    sftp.put('/home/source/workspace/vddir', '/home/destinatiob/workspace/vddir')
  File "/usr/local/lib/python3.6/dist-packages/paramiko/sftp_client.py", line 758, in put
    with open(localpath, "rb") as fl:
IsADirectoryError: [Errno 21] Is a directory: '/home/appadmin/workspace/vdcode'

请帮忙...提前谢谢


共1个答案

匿名用户

问题是你不能一次移动整个文件夹,你必须浏览文件并逐个上传。这应该回答您的问题:https://stackoverflow.com/a/19974994/7838574