git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

pysftp / paramiko problem


On 2019-06-13 14:57, Robin Becker wrote:
> On 13/06/2019 05:56, dieter wrote:
>> Robin Becker <robin at reportlab.com> writes:
>>> On 12/06/2019 05:59, dieter wrote:
>>>> Robin Becker <robin at reportlab.com> writes:
>>>>> I am trying to convert older code that uses ftplib as the endpoint has switched to sftp only.
>>> ...
>>> Well with real sftp I can cd to that path so if it is a symlink it goes somewhere.
>>>
>>> With pysftp I am unable to chdir or cd into it. With a bit of
>>> difficulty I can use subprocess + sshpass + sftp to do the required
>>> transfer.
>> 
>> Maybe, the problem is the "u" prefix.
>> Can you try your script with Python 3 or encode the unicode
>> into a native ``str``?
>> 
> no same happens in a fresh python 3.6 environment
> 
>> $ cat - > tsftp.py
>> def main():
>>     import pysftp
>>     with pysftp.Connection('ftp.remote.com', username='me', password='ucl20                                                                 11') as sftp:
>>         print('top level')
>>         print(sftp.listdir())
>>         print(sftp.normalize('XXXX'))
>> 
>> if __name__ == '__main__':
>>     main()
>> (tpy3) rptlab at app1:~/tmp/tpy3
>> $ python tsftp.py
>> top level
>> ['XXXX']
>> Traceback (most recent call last):
>>   File "tsftp.py", line 9, in <module>
>>     main()
>>   File "tsftp.py", line 6, in main
>>     print(sftp.normalize('XXXX'))
>>   File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/pysftp/__init__.py", line 640, in normalize
>>     return self._sftp.normalize(remotepath)
>>   File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 632, in normalize
>>     t, msg = self._request(CMD_REALPATH, path)
>>   File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 813, in _request
>>     return self._read_response(num)
>>   File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 865, in _read_response
>>     self._convert_status(msg)
>>   File "/home/rptlab/tmp/tpy3/lib/python3.6/site-packages/paramiko/sftp_client.py", line 894, in _convert_status
>>     raise IOError(errno.ENOENT, text)
>> FileNotFoundError: [Errno 2] No such file.
> 
> this is what real sftp does
> 
>> (tpy3) rptlab at app1:~/tmp/tpy3
>> $ sshpass -p ucl2011 sftp me at ftp.remote.com
>> Connected to ftp.remote.com.
>> sftp> cd XXXX
>> sftp> pwd
>> Remote working directory: /XXXX
>> sftp> ls
>> OLD GR ........
>>   ZZZZZ.pdf
>> sftp> ^D
>> (tpy3) rptlab at app1:~/tmp/tpy3
> 
What does:

sftp.normalize('.')

return?