Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
856 views
in Technique[技术] by (71.8m points)

python - Uploading file via Paramiko SFTP not working

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.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

Try this:

sftp.put(filePath, "/filename")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...