user997112
user997112

Reputation: 30615

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?

Upvotes: 8

Views: 15264

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202272

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")

Upvotes: 16

Related Questions