Python/Parimiko error: FileNotFoundError: [Errno 2] No such file

Python/Parimiko error: FileNotFoundError: [Errno 2] No such file

我有以下脚本:

import pysftp as sftp

def sftp_send():
    try:
        s = sftp.Connection(host='****', username='****', password='****')
    remotepath = '/var/sftp/uploads'
    localpath='ds/test.txt'
    s.put(localpath, remotepath)
    s.close()

except Exception as e:
    raise e

sftp_send()

当 运行 时它抛出 "No such file" 错误。当我将 'localpath' 变量更改为:

localpath = 'ds' 

it returns a 'ds is a directory',所以它标识了到此为止的路径。但是,一旦我添加文件名,就会发生上述错误。我看过几个类似的问题,建议查看 remote/local 权限,但似乎没有一个确凿的答案。有什么想法吗?

remotepath 也应该包含文件名,所以 remotepath='/var/sftp/uploads/filename.txt'

这个怎么样!

import pysftp

with pysftp.Connection('hostname', username='me', password='secret') as sftp:
    with sftp.cd('public'):             # temporarily chdir to public
        sftp.put('/my/local/filename')  # upload file to public/ on remote  

来源:https://pysftp.readthedocs.io/en/release_0.2.9/