jbardin / scp.py

scp module for paramiko
Other
529 stars 139 forks source link

scp does not work with pathlib.PurePath #169

Closed amatyukhin0 closed 2 years ago

amatyukhin0 commented 2 years ago

scp does not completely support pathlib paths:

>>> ssh_client = paramiko.SSHClient()
>>> ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh_client.connect(hostname='*****', username='test-user')
>>> scp_client = scp.SCPClient(ssh_client.get_transport())
>>> src = pathlib.Path(r'C:\users\test-user\test.txt')
>>> dst = pathlib.PurePosixPath('/home/test-user/test.txt')
>>> scp_client.put(src, dst)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Work\Pythons\yin\bin\lib\site-packages\scp.py", line 174, in put
    self.sanitize(asbytes(remote_path)))
  File "C:\Work\Pythons\yin\bin\lib\site-packages\scp.py", line 59, in asbytes
    return s.encode('utf-8')
AttributeError: 'PurePosixPath' object has no attribute 'encode'
remram44 commented 2 years ago

Fixed by 8ea04a03, thanks