1
時,我想使用Python「沒有這樣的文件」錯誤使用的paramiko的SFTP
#!/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
的錯誤。如果你知道答案後。請讓我知道
感謝閱讀..
@ shx2謝謝,是的,我有一個上面提到的路徑文件。 – Anand
@ shx2,我在遠程目錄路徑上犯了一個錯誤。現在是工作。謝謝 – Anand
太棒了!我將我的評論轉換爲答案 – shx2