0

I want to execute a simple scp command in a python script, copying files following a certain name pattern.

I'm executing the following command:

filename = '\*last_processed_date\*.txt'
command = ''' scp test@100.41.14.27:/home/test/test2/test3/%s %s '''\
                      % (filename,self.unprocessed_file_dir)
os.system(command)

I understand that I have to escape the wildcard '*', which I'm doing..but still I get:

scp: /home/test/test2/test3/*last_processed_date*.txt: No such file or directory

I'm wondering what I'm doing wrong..

EDIT: It was a careless mistake from my side. I should have done:

command = ''' scp 'test@100.41.14.27:/home/test/test2/test3/%s' %s '''

instead of:

command = ''' scp test@100.41.14.27:/home/test/test2/test3/%s %s '''\
                          % (filename,self.unprocessed_file_dir)
Saurabh Verma
  • 6,328
  • 12
  • 52
  • 84

1 Answers1

1

This works on my system:

host = 'test@100.41.14.27'
filename = '*last_processed_date*.txt'
rpath = '/home/test/test2/test3'
lpath = self.unprocessed_file_dir
command = 'scp %s:%s/%s %s' % (host, rpath, filename, lpath)
os.system(command)

If it gives you an error, try this on from the terminal first:

ssh test@100.41.14.27 ls /home/test/test2/test3/*last_processed_date*.txt
perreal
  • 94,503
  • 21
  • 155
  • 181