2014-04-15 69 views
0

我想在python腳本中執行一個簡單的scp命令,按照特定的名稱模式複製文件。在python中使用scp中的文件名中的通配符

我執行以下命令:

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

我明白,我必須逃離通配符 '*',這我doing..but還是我得到:

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

我想知道我做錯了什麼..

編輯: 這是一個粗心的錯誤從我身邊。我應該這樣做:代替

command = ''' scp '[email protected]:/home/test/test2/test3/%s' %s ''' 

command = ''' scp [email protected]:/home/test/test2/test3/%s %s '''\ 
          % (filename,self.unprocessed_file_dir) 
+0

嘗試原始字符串。 – Rahul

+0

試過,它沒有工作。 –

回答

1

這個作品在我的系統上:

host = '[email protected]' 
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) 

如果給你一個錯誤,從終端第一次嘗試這樣的:

ssh [email protected] ls /home/test/test2/test3/*last_processed_date*.txt 
相關問題