在python中的scp文件名中使用通配符 [英] Using wildcards in filename in scp in python
本文介绍了在python中的scp文件名中使用通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 python 脚本中执行一个简单的 scp 命令,按照特定的名称模式复制文件.
I want to execute a simple scp command in a python script, copying files following a certain name pattern.
我正在执行以下命令:
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..
从我的角度来看,这是一个粗心的错误.我应该这样做:
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 '''
代替:
command = ''' scp test@100.41.14.27:/home/test/test2/test3/%s %s '''\
% (filename,self.unprocessed_file_dir)
推荐答案
这适用于我的系统:
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
这篇关于在python中的scp文件名中使用通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文