【发布时间】:2012-05-11 02:57:00
【问题描述】:
我们如何通过在 python 脚本中使用 os.system 调用 unix shell 命令,将文件从源主机 sftp 到目标服务器...请帮助
I have tried the following code
dstfilename="hi.txt"
host="abc.com"
user="sa"
os.system("echo cd /tmp >sample.txt)
os.system("echo put %(dstfilename)s" %locals()) // line 2
os.system("echo bye >>sample.txt")
os.system("sftp -B /var/tmp/sample.txt %(user)s@%(host)s)
How to append this result of line to sample.txt?
os.system("echo put %(dstfilename)s %locals()) >>sample.txt" // Seems this is syntatically not correct.
cat>sample.txt //should look like this
cd /tmp
put /var/tmp/hi.txt
bye
Any help?
Thanks you
【问题讨论】:
-
为什么要使用
os.system向文件写入行?为什么不只是open和print?