ParallelSSH / ssh2-python

Python bindings for libssh2 C library.
https://parallel-ssh.org
GNU Lesser General Public License v2.1
228 stars 72 forks source link

scp does not work when using userauth_password #78

Closed aveach closed 5 years ago

aveach commented 5 years ago

I'm writing a very simple wrapper for ssh2-python and trying to get scp to work (neither scp_send64 nor scp_recv2 seem to be working).

For simplicity (in case I was doing something stupid in my wrapper) I modified one line in example/scp_write.py to use userauth_password instead as follows:

diff --git a/examples/scp_write.py b/examples/scp_write.py
index a29aa24..b21a9c3 100755
--- a/examples/scp_write.py
+++ b/examples/scp_write.py
@@ -34,7 +34,8 @@ def main():
     sock.connect((args.host, args.port))
     s = Session()
     s.handshake(sock)
-    s.agent_auth(args.user)
+    # s.agent_auth(args.user)
+    s.userauth_password("root", "") 
     fileinfo = os.stat(args.source)
     chan = s.scp_send64(args.destination, fileinfo.st_mode & 0o777, fileinfo.st_size,
                         fileinfo.st_mtime, fileinfo.st_atime)

and although it shows the transfer completes sucessfully:

$ python3 scp_write.py ~/Desktop/client.py /tmp --host ap
Starting SCP of local file ../Desktop/client.py to remote ap:/tmp
Finished writing remote file in 0:00:00.003666, transfer rate 1.4248862009001637 MB/s

The file never actually shows up on the remote machine. (This works without issue using standard scp in a terminal)

aveach commented 5 years ago

FWIW, I tried using pssh.clients.native.single.SSHClient.scp_send as well and same scenario. No exceptions are raised but the file is not on the remote machine.

>>> from pssh.clients.native.single import SSHClient
>>> s = SSHClient("ap", "root", "")
>>> s.scp_send("../Desktop/client.py", "/tmp")
>>> r = s.run_command("ls /tmp")
>>> print(*r[2])
log_tmp.log
pkittenis commented 5 years ago

Hi there,

Seems like the code is trying to write a file to a directory. The destination path needs to be a file.

Authentication method does not play any part in how SCP or any other functionality works - if client is authenticated it's all the same.

Does this not work?

python3 scp_write.py ~/Desktop/client.py /tmp/client.py
aveach commented 5 years ago

wow... I swear I tried that. 🤦‍♂

Thanks @pkittenis, sorry for the churn