我想使用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
如果您知道答案。请告诉我
谢谢阅读..
最佳答案
问题很可能是远程目录不存在(/home/developers/screenshots
)。创建目录,然后重试。
关于python - 使用paramiko的sftp时"No such file"错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20142059/