pytest-sftpserver
pytest-sftpserver copied to clipboard
Problem using put with sftpclient
I'm having some problems using put on sftpclient, I always get an exception and it does not work for me.
In the most simple example I have pytest and pytest-sftpserver installed in a virtual environment (I have tried with both python 2.7 and python 3.8).
Using this test:
from paramiko import Transport
from paramiko.channel import Channel
from paramiko.sftp_client import SFTPClient
def test_sftp(sftpserver):
transport = Transport((sftpserver.host, sftpserver.port))
transport.connect(username="a", password="b")
sftpclient = SFTPClient.from_transport(transport)
try:
assert sftpclient.listdir("/") == []
sftpclient.put("temp.txt", "/a/test.txt")
finally:
sftpclient.close()
transport.close()
I get this error:
test.py:12:
local/lib/python2.7/site-packages/paramiko/sftp_client.py:759: in put return self.putfo(fl, remotepath, file_size, callback, confirm) local/lib/python2.7/site-packages/paramiko/sftp_client.py:720: in putfo s = self.stat(remotepath) local/lib/python2.7/site-packages/paramiko/sftp_client.py:493: in stat t, msg = self._request(CMD_STAT, path) local/lib/python2.7/site-packages/paramiko/sftp_client.py:813: in _request return self._read_response(num) local/lib/python2.7/site-packages/paramiko/sftp_client.py:865: in _read_response self._convert_status(msg)
self = <paramiko.sftp_client.SFTPClient object at 0x7f360daa0fd0>, msg = paramiko.Message('\x00\x00\x00\x07\x00\x00\x00\x02\x00\x00\x00\x0cNo such file\x00\x00\x00\x00')
def _convert_status(self, msg): """ Raises EOFError or IOError on error status; otherwise does nothing. """ code = msg.get_int() text = msg.get_text() if code == SFTP_OK: return elif code == SFTP_EOF: raise EOFError(text) elif code == SFTP_NO_SUCH_FILE: # clever idea from john a. meinel: map the error codes to errno raise IOError(errno.ENOENT, text)
E IOError: [Errno 2] No such file
I don't understand what is wrong. Any help would be greatly appreciated.
I'm debugging some similar issues.
What do you get if you replace
sftpclient.put("temp.txt", "/a/test.txt")
by sftpclient.put("temp.txt", "/test.txt")
i.e. put it in an already existing folder?
The issue you have seems to be that you're trying to upload to a folder that does not exist yet
Hi, sorry for the late response. I have tried as you said and I still get the same error.