使用 Paramiko 在 SFTP 中“放入" [英] 'put' in SFTP using Paramiko
本文介绍了使用 Paramiko 在 SFTP 中“放入"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经安装并编写了以下无法放置文件的Paramiko.它可以轻松地获取"文件并对其执行 ls
命令.
I've installed and written the following Paramiko which is unable to put the file. It is easily able to 'get' a file and execute ls
commands on it.
#set username & password
username='runaway'
password='runaway'
port=22
source= '/Unzip.sh'
destination ='/var/mpx/www/http'
#SFTP
client.load_system_host_keys()
print " hostname =%s \n username=%s \n password=%s \n" (hostname,username,password)
t = paramiko.Transport((hostname, port))
t.connect(username=username,password=password)
sftp = paramiko.SFTPClient.from_transport(t)
sftp.put(source,destination)
#sftp.close()
#t.close()
使用put"命令会出现以下错误 &堆栈跟踪 -
Using a 'put' command gives the following error & stack trace -
File "upload_file.py", line 84, in ?
sftp.put(source,destination)
File "/usr/lib/python2.4/site-packages/paramiko/sftp_client.py", line 522, in put
fr = self.file(remotepath, 'wb')
File "/usr/lib/python2.4/site-packages/paramiko/sftp_client.py", line 221, in open
t, msg = self._request(CMD_OPEN, filename, imode, attrblock)
File "/usr/lib/python2.4/site-packages/paramiko/sftp_client.py", line 572, in _request
return self._read_response(num)
File "/usr/lib/python2.4/site-packages/paramiko/sftp_client.py", line 619, in _read_response
self._convert_status(msg)
File "/usr/lib/python2.4/site-packages/paramiko/sftp_client.py", line 649, in _convert_status
raise IOError(text)
IOError: Failure
我该如何克服这个问题?
How do I overcome this?
推荐答案
我觉得这个解决方案很有趣!
The solution seemed very funny to me!
source= '/Unzip.sh'
destination ='/var/mpx/www/http/Unzip.sh'
刚刚修改了目标路径以包含文件名.没想到 Python 包会出现这样的错误.
Just modified the destination path to include the file name as well. Didn't expect some error like this coming from a Python package.
这篇关于使用 Paramiko 在 SFTP 中“放入"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文