Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 views
in Technique[技术] by (71.8m points)

python - 'put' in SFTP using Paramiko

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 
 username=%s 
 password=%s 
" (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()

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The solution seemed very funny to me!

source= '/Unzip.sh' 
destination ='/var/mpx/www/http/Unzip.sh'

Just modified the destination path to include the file name as well. Didn't expect some error like this coming from a Python package.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...