通过 Paramiko SFTP 上传文件不起作用 [英] Uploading file via Paramiko SFTP not working

查看:73
本文介绍了通过 Paramiko SFTP 上传文件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下 Python 代码使用 Paramiko 通过 SFTP 上传文件.连接似乎"好吧,代码执行到最后,只是当我签入 FileZilla 时文件没有到达目的地.

I am using the below Python code to upload a file via SFTP using Paramiko. The connection "seems" to be fine, the code executes to the end, just the file isn't reaching the destination when I check in FileZilla.

我已检查文件的权限并将其设置为 777(只是为了确定).我还在一个单独的终端中检查了我的文件路径字符串并且路径是有效的.

I have checked and set permissions on the file to 777 (just to be sure). I have also checked my file path string in a separate terminal and the path is valid.

import paramiko
.
.

transport = paramiko.Transport((host, port))
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)

sftp.put(filePath, "/")  # Upload file to root FTP folder
sftp.close()
transport.close()

我能做些什么来调试这个?我可以打印出任何东西,检查连接是否成功等?

What can I do to debug this? Anything I can print out, check connection succeeded etc?

推荐答案

SFTPClient.put (remotepath) 是文件的路径,而不是文件夹:

The second argument of SFTPClient.put (remotepath) is path to a file, not a folder:

SFTP 服务器上的目标路径.请注意,应包括文件名.仅指定目录可能会导致错误.

the destination path on the SFTP server. Note that the filename should be included. Only specifying a directory may result in an error.

试试这个:

sftp.put(filePath, "/filename")

这篇关于通过 Paramiko SFTP 上传文件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆