我正在尝试使用scp复制本地网络中的文件。它可以与没有空格的文件名一起很好地工作,但是会崩溃。我已尝试将“”替换为“ \”,例如,但这是行不通的。这是我的代码:
def connection(locals):
a = (int(re.search(br'(\d+)%$', locals['child'].after).group(1)))
print a
perc = (Decimal(a)/100)
print (type(perc)), perc
while gtk.events_pending():
gtk.main_iteration()
FileCopy.pbar.set_text("Copy of the file in the Pi... " + str(a) + "%")
while gtk.events_pending():
gtk.main_iteration()
FileCopy.pbar.set_fraction(perc)
file_pc = "/home/guillaume/folder/a very large name of file with space .smthg"
file_pi = "[email protected]:/home/pi/folder/a very large name of file with space .smthg"
if " " in file_pc:
file_pc = fichier_pc.replace(" ", '\\\ ') # tried '\\ ' or '\ '
file_pi = fichier_pi.replace(" ", '\\\ ') # but no way
else:
pass
command = "scp %s %s" % tuple(map(pipes.quote, [file_pc, file_pi]))
pexpect.run(command, events={r'\d+%': connection}) # this command is using to get the %
我该如何解决这个问题?谢谢
您可以file_pc
按原样保留本地文件(pipes.quote
将转义空格)。远程文件应更改:
import pipes
file_pi = '[email protected]:/home/pi/folder/file with space.smth'
host, colon, path = file_pi.partition(':')
assert colon
file_pi = host + colon + pipes.quote(path)
即,user@host:/path/with space
应更改为user@host:'/path/with space'
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句