Paramiko 在将文件传输到目录时出错 IsADirectoryError: [Errno 21] Is a directory: '/home/mmoradi2/data/' [英] Paramiko through error while transferring file to a directory IsADirectoryError: [Errno 21] Is a directory: '/home/mmoradi2/data/'

查看:550
本文介绍了Paramiko 在将文件传输到目录时出错 IsADirectoryError: [Errno 21] Is a directory: '/home/mmoradi2/data/'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在两台服务器之间传输文件.我用过Paramiko.有一个名为data"的目录,但它说:

I try to transfer a file between two servers. I used Paramiko. There is a directry called "data" but it says:

IsADirectoryError: [Errno 21] 是一个目录:'/home/mmoradi2/data/'

IsADirectoryError: [Errno 21] Is a directory: '/home/mmoradi2/data/'

我不知道是什么问题.这是我的代码:

I have no idea what is the problem. This is my code:

import paramiko

s = paramiko.SSHClient()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(hostname='****8', username='****',password='****',port=22)
sftp = s.open_sftp()


list_files_share_drive = sftp.listdir('./')

# Looping through the files and transferring them to the data folder and importing them

the_file = list_files_share_drive[0]

sftp.get( '/home/sftpwis/'+ the_file  ,   '/home/mmoradi2/data/')

我将目标 ('/home/mmoradi2/data/') 更改为:'/家/mmoradi2/数据'和'/home/mmoradi2'

I changed the target ('/home/mmoradi2/data/') to: '/home/mmoradi2/data' and '/home/mmoradi2'

它不起作用,我遇到了同样的错误.我将其更改为/home/mmoradi2/Data/".然后我没有错误,但是有一个我无法 cd 到它的新目录!!!(打不开)

It did not work and I had the same error. I changed it to '/home/mmoradi2/Data/'. then I had no error but there is a new directry that I cannot cd to it!!! (cannot open it)

我该如何解决这个问题?

How can I fix this problem?

推荐答案

SFTPClient.get() 方法是放置文件的本地路径.这不是它应该放入的目录,而是它应该复制到的实际文件名.解决方法只是将您的线路更改为

The second argument to the SFTPClient.get() method is the local path where the file should be put. This is not the directory that it should be put into, but the actual file name that it should be copied to. The fix is simply to change your line to

sftp.get( '/home/sftpwis/'+ the_file  ,   '/home/mmoradi2/data/' + the_file)

错误信息相当合理——它说你给出的路径是一个目录;这意味着它需要一个不是目录的路径,即它是一个常规文件名.

The error message is fairly reasonable - it says that the path you have given is a directory; that implies that it is expecting a path that is not a directory, i.e., it is a regular file name.

您拥有的 Data 条目不是目录(看看它与其他目录的颜色有何不同?),而是您从远程服务器检索的文件.

The Data entry you have is not a directory (see how it is a different colour to the other directories?), it is the file that you have retrieved from the remote server.

这篇关于Paramiko 在将文件传输到目录时出错 IsADirectoryError: [Errno 21] Is a directory: '/home/mmoradi2/data/'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆