我想使用python
将文件传输到服务器#!/usr/bin/env python
import os
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname, username="username", password="password")
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('ls /tmp')
print "output", ssh_stdout.read()
#Reading output of the executed command
error = ssh_stderr.read()
#Reading the error stream of the executed command
print "err", error, len(error)
#Transfering files to and from the remote machine
sftp = ssh.open_sftp()
#sftp.get("/home/developers/screenshots/ss.txt", "/home/e100075/python/ss.txt")
sftp.put('/home/e100075/python/ss.txt', '/home/developers/screenshots/ss.txt')
sftp.close()
ssh.close()
跑完后我得到了以下错误
File "file_copy.py", line 21, in <module>
sftp.put('/home/e100075/python/ss.txt', '/home/developers/screenshots/ss.txt')
File "/usr/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 565, in put
fr = self.file(remotepath, 'wb')
File "/usr/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 245, in open
t, msg = self._request(CMD_OPEN, filename, imode, attrblock)
File "/usr/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 635, in _request
return self._read_response(num)
File "/usr/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 682, in _read_response
self._convert_status(msg)
File "/usr/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 708, in _convert_status
raise IOError(errno.ENOENT, text)
IOError: [Errno 2] No such file
如果你知道答案。请让我知道
感谢阅读..
答案 0 :(得分:1)
问题很可能是远程目录不存在(/home/developers/screenshots
)。创建目录,然后重试。