[英]sftp issues using pysftp
I'm trying to send a file from local machine to server thru sftp using pysftp我正在尝试使用 pysftp 通过 sftp 将文件从本地计算机发送到服务器
When I login to the server using command line as:当我使用命令行登录到服务器时:
sftp -o port=111 user_name@host
then do pwd
I get the /
as the current location然后做
pwd
我得到/
作为当前位置
So I want to do the same in pysftp
as:所以我想在
pysftp
做同样的pysftp
:
import pysftp
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
with pysftp.Connection("host", username="user_name", password="password", port=111, cnopts=cnopts) as sftp:
print(sftp.pwd)
sftp.put(local_file, sftp.pwd)
but I get the error IOError: [Errno 13] Permission denied
但我收到错误
IOError: [Errno 13] Permission denied
Although, I'm able to sftp using the same credentials in command line and an ftp client like FileZilla虽然,我能够在命令行和像 FileZilla 这样的 ftp 客户端中使用相同的凭据进行 sftp
Here the full error trace:这里是完整的错误跟踪:
traceback (most recent call last):
File "C:/workspace/segments-upload/media_math_segments_upload.py", line 232, in <module>
sys.exit(0 if main() else 1)
File "C:/workspace/segments-upload/media_math_segments_upload.py", line 226, in main
process(s3_bucket, s3_dir, sftp_host, sftp_path, sftp_user_name, sftp_password, sftp_port)
File "C:/workspace/segments-upload/media_math_segments_upload.py", line 182, in process
sftp_file(local_file, sftp_host, sftp_path, sftp_user_name, sftp_password, sftp_port)
File "C:/workspace/segments-upload/media_math_segments_upload.py", line 105, in sftp_file
sftp.put(local_file, sftp.pwd)
File "C:\Users\tkaghdo\AppData\Local\Continuum\Anaconda2\lib\site-packages\pysftp\__init__.py", line 364, in put
confirm=confirm)
File "C:\Users\tkaghdo\AppData\Local\Continuum\Anaconda2\lib\site-packages\paramiko\sftp_client.py", line 676, in put
return self.putfo(fl, remotepath, file_size, callback, confirm)
File "C:\Users\tkaghdo\AppData\Local\Continuum\Anaconda2\lib\site-packages\paramiko\sftp_client.py", line 634, in putfo
with self.file(remotepath, 'wb') as fr:
File "C:\Users\tkaghdo\AppData\Local\Continuum\Anaconda2\lib\site-packages\paramiko\sftp_client.py", line 327, in open
t, msg = self._request(CMD_OPEN, filename, imode, attrblock)
File "C:\Users\tkaghdo\AppData\Local\Continuum\Anaconda2\lib\site-packages\paramiko\sftp_client.py", line 730, in _request
return self._read_response(num)
File "C:\Users\tkaghdo\AppData\Local\Continuum\Anaconda2\lib\site-packages\paramiko\sftp_client.py", line 781, in _read_response
self._convert_status(msg)
File "C:\Users\tkaghdo\AppData\Local\Continuum\Anaconda2\lib\site-packages\paramiko\sftp_client.py", line 809, in _convert_status
raise IOError(errno.EACCES, text)
IOError: [Errno 13] Permission denied
The issue was resolved by providing the name of the file on the remote server.该问题已通过提供远程服务器上的文件名解决。 So I just changed
所以我只是改变了
sftp.put(local_file, sftp.pwd)
to到
sftp.put(local_file, "file_name.dat")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.