From 0c4669cd05e3dafe29f362ba3ca1fd353c66b67e Mon Sep 17 00:00:00 2001 From: Martin Ulmschneider Date: Thu, 10 Dec 2015 16:21:38 +0100 Subject: [PATCH] Convert scp port to str Otherwise b_list(cmd) will raise an Exception because it can't encode the int. Also added a test for this. --- openssh_wrapper.py | 2 +- tests.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/openssh_wrapper.py b/openssh_wrapper.py index 741da66..a421017 100644 --- a/openssh_wrapper.py +++ b/openssh_wrapper.py @@ -369,7 +369,7 @@ def scp_command(self, files, target): if self.identity_file: cmd += ['-i', self.identity_file] if self.port: - cmd += ['-P', self.port] + cmd += ['-P', str(self.port)] if isinstance(files, (text, bytes)): raise ValueError('"files" argument have to be iterable (list or tuple)') diff --git a/tests.py b/tests.py index b27d02d..b6e01e1 100644 --- a/tests.py +++ b/tests.py @@ -71,6 +71,16 @@ def test_scp(self): self.c.scp((test_file, ), target='/tmp') assert os.path.isfile('/tmp/tests.py') + def test_scp_int_port(self): + c = SSHConnection('localhost', login='root', port=22) + c.scp((test_file, ), target='/tmp') + assert os.path.isfile('/tmp/tests.py') + + def test_scp_str_port(self): + c = SSHConnection('localhost', login='root', port='22') + c.scp((test_file, ), target='/tmp') + assert os.path.isfile('/tmp/tests.py') + def test_scp_to_nonexistent_dir(self): with pytest.raises(SSHError): self.c.scp((test_file, ), target='/abc/def/')