这个问题在这里已经有了答案:
Python Paramiko, PermissionError: [Errno 13] Permission denied when get files from remote server
(1 个回答)
去年关闭。
我尝试在两台服务器之间传输文件。
我用了 Paramiko 。有一个名为“数据”的目录,但它说:
IsADirectoryError: [Errno 21] Is a directory: '/home/mmoradi2/data/'
我不知道是什么问题。这是我的代码:
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/')更改为:
'/home/mmoradi2/数据'
和
'/home/mmoradi2'
它没有用,我遇到了同样的错误。我将其更改为“/home/mmoradi2/Data/”。然后我没有错误,但是有一个新目录我不能 cd 到它!!! (打不开)
我该如何解决这个问题?
最佳答案
SFTPClient.get()
的第二个参数方法是应该放置文件的本地路径。这不是它应该放入的目录,而是它应该复制到的实际文件名。解决方法只是将您的线路更改为
sftp.get( '/home/sftpwis/'+ the_file , '/home/mmoradi2/data/' + the_file)
错误信息是相当合理的——它说你给出的路径是一个目录;这意味着它需要一个不是目录的路径,即它是一个常规文件名。
Data
您拥有的条目不是目录(看看它与其他目录的颜色有何不同?),它是您从远程服务器检索的文件。
关于python - Paramiko 在将文件传输到目录时出错 IsADirectoryError : [Errno 21] Is a directory: '/home/mmoradi2/data/' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62182836/