|
23 | 23 | import gevent |
24 | 24 | import socket |
25 | 25 | import time |
| 26 | +import shutil |
26 | 27 | import unittest |
27 | 28 | from pssh import SSHClient, ParallelSSHClient, UnknownHostException, AuthenticationException,\ |
28 | 29 | logger, ConnectionErrorException, UnknownHostException, SSHException |
@@ -141,6 +142,49 @@ def test_ssh_client_sftp(self): |
141 | 142 | os.rmdir(dirpath) |
142 | 143 | del client |
143 | 144 |
|
| 145 | + def test_ssh_client_directory(self): |
| 146 | + """Tests copying directories with SSH client. Copy all the files from |
| 147 | + local directory to server, then make sure they are all present.""" |
| 148 | + test_file_data = 'test' |
| 149 | + local_test_path = 'directory_test' |
| 150 | + remote_test_path = 'directory_test_copied' |
| 151 | + os.mkdir(local_test_path) |
| 152 | + remote_file_paths = [] |
| 153 | + for i in range(0, 10): |
| 154 | + local_file_path = os.path.join(local_test_path, 'foo' + str(i)) |
| 155 | + remote_file_path = os.path.join(remote_test_path, 'foo' + str(i)) |
| 156 | + remote_file_paths.append(remote_file_path) |
| 157 | + test_file = open(local_file_path, 'w') |
| 158 | + test_file.write(test_file_data) |
| 159 | + test_file.close() |
| 160 | + client = SSHClient(self.host, port=self.listen_port, |
| 161 | + pkey=self.user_key) |
| 162 | + client.copy_file(local_test_path, remote_test_path, recurse=True) |
| 163 | + for path in remote_file_paths: |
| 164 | + self.assertTrue(os.path.isfile(path)) |
| 165 | + shutil.rmtree(local_test_path) |
| 166 | + shutil.rmtree(remote_test_path) |
| 167 | + |
| 168 | + def test_ssh_client_directory_no_recurse(self): |
| 169 | + """Tests copying directories with SSH client. Copy all the files from |
| 170 | + local directory to server, then make sure they are all present.""" |
| 171 | + test_file_data = 'test' |
| 172 | + local_test_path = 'directory_test' |
| 173 | + remote_test_path = 'directory_test_copied' |
| 174 | + os.mkdir(local_test_path) |
| 175 | + remote_file_paths = [] |
| 176 | + for i in range(0, 10): |
| 177 | + local_file_path = os.path.join(local_test_path, 'foo' + str(i)) |
| 178 | + remote_file_path = os.path.join(remote_test_path, 'foo' + str(i)) |
| 179 | + remote_file_paths.append(remote_file_path) |
| 180 | + test_file = open(local_file_path, 'w') |
| 181 | + test_file.write(test_file_data) |
| 182 | + test_file.close() |
| 183 | + client = SSHClient(self.host, port=self.listen_port, |
| 184 | + pkey=self.user_key) |
| 185 | + self.assertRaises(ValueError, client.copy_file, local_test_path, remote_test_path) |
| 186 | + shutil.rmtree(local_test_path) |
| 187 | + |
144 | 188 | def test_ssh_agent_authentication(self): |
145 | 189 | """Test authentication via SSH agent. |
146 | 190 | Do not provide public key to use when creating SSHClient, |
|
0 commit comments