I am trying to put together an SFTP module for use with a drone in a project for school. Security is not a concern for me right now, as I am simply trying to get successful connections and file transfers established first.
import paramiko
#Open Transport
host, port = "IP Address", 22
transport = paramiko.Transport((host,port))
#Authentication
username, password = "Username", "Password"
transport.connect(None, username, password)
#Connect
sftp = paramiko.SFTPClient.from_transport(transport)
#Download
remotePath = "C:\\Users\\User\\Desktop\\Upload Data\\Test.txt"
localPath = "C:\\Users\\User\\Downloads\\Test.txt"
sftp.get(remotePath, localPath)
#Upload
remotePath = "C:\\Users\\User\\Desktop\\Upload Data"
localPath = "C:\\Users\\User\\Downloads\\Test.txt"
sftp.put(localPath, remotePath)
#Close
if sftp: sftp.close()
if transport: transport.close()
When running the above code, I get FileNotFound: [Errno 2] No such file
returned. The same error is returned for attempted uploads. I am hosting the SFTP server on a Windows platform using OpenSSH, as the paths may suggest.
The sshd_config
file is pointing correctly to the path defined in remotePath
. Firewall rules on the server are correctly configured, as I am able to connect to the SFTP server using FileZilla from the same computer I am attempting to connect to the server from using Python. I can ping the remote server using the same machine as well. As far as I can tell, this is not a connectivity issue between the server and client.
I'm really not sure what I am doing wrong. I have quadruple checked the paths in my code are correct. I have been knee-deep in tabs for the past couple of hours trying to troubleshoot, but I'm running out of ideas and so I need to ask the internet.