0

I am using scp to download files from unix to windows machine. I am able to download one file at a time. How can i download files with like option ? I am able to download below. scp.get('/abc/def/input/interface.20200812.6543.log')

How do i do something like below to download multiple files as i dont know what should be exact names of files:

scp.get('/abc/def/input/interface.today's date.*.log')

1 Answers1

0

As pointed out in the docstring of the SCPClient.get method, the remote path is evaluated by scp on the remote host, so what you have in the question, with wildcards in the remote path, should work, e.g.:

import datetime
scp.get(f'/abc/def/input/interface.{datetime.date.today().strftime('%y%m%d')}.*.log')
blhsing
  • 91,368
  • 6
  • 71
  • 106
  • It does not seem to work. I'm afraid the documentation is wrong. `SCPClient` seems to escape all special characters. – Martin Prikryl Aug 28 '20 at 13:45
  • Yes, it's not working. SCPClient is only accepting full names of files. Does not allow * in files names. – Sunil Kumar Mandal Aug 31 '20 at 17:04
  • def get_copy(self, hostname, dst): ssh = createSSHClient(hostname) stdin, stdout, stderr = ssh.exec_command('ls /home/username/*output') result = stdout.read().split() scp = SCPClient(ssh.get_transport()) for per_result in result: scp.get(per_result) scp.close() ssh.close() Found above and is working. – Sunil Kumar Mandal Aug 31 '20 at 17:17
  • Yes, if wildcard doesn't work then you would unfortunately have to use ssh to get the directory listing yourself and iterate over the desired set of files within the listing to scp from individually. – blhsing Aug 31 '20 at 17:24