Reputation: 11
I'm fairly new to Python and migrating an already running script to a new machine. The key part of the script is to ftp a file to internal file server. A snippet of code is:
import pysftp
with pysftp.connection(host="hostname",username="uname",password="pwd") as sftp:
sftp.put("d://folder1//file1.txt","file1.txt")
this code throws the following Error:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "folder//sftp.py", line 349, in put confirm=confirm)
File "...\paramiko\sftp_client.py", line 669 in put return self.putfo(f1, remotepath, file_size, callback, confirm)
File "...\paramiko\sftp_client.py", line 633 in putfo s = self.stat(remotepath)
File "...\paramiko\sftp_client.py", line 413 in stat t, msg = self.request(CMD_STAT, path)
File "...\paramiko\sftp_client.py", line 729 in _request return self.read_response(num)
File "...\paramiko\sftp_client.py", line 776 in _read_response self.convert_status(msg)
File "...\paramiko\sftp_client.py", line 802 in _convert_status raise IOError(errno.ENOENT, text)
IOError: [Errno 2] No such file
However, the ftp file can be accessed succesfully as below:
f= open("d://folder//file1.txt",r)
print (f.read())
have you seen such error? any idea how to overcome this error?
Appreciate your help, Thanks
Upvotes: 0
Views: 185
Reputation: 675
I think it can help:)
import pysftp
with pysftp.Connection(host="hostname", username="uname", password="pwd") as sftp:
local_path = "d://folder1//file1.txt"
remote_path = "/path/to/remote/directory/file1.txt" # replace with real remote path
sftp.put(local_path, remote_path)
Upvotes: 0