如何使用Python 2.7中的OS.Popen()或OS.System()方法来执行WINSCP命令


import os
WINSCP = r'C:Program Files (x86)WinSCPWinSCP.com' # the path of winscp in my system
command = "winscp /console /script=SFTP.txt /parameter /opt/outgo/aftp/20161222.zip.pgp C:UsersAbhDesktop\"
stdin, stdout = os.popen2(WINSCP + command)

我正在尝试使用OS模块的Popen函数执行此WINSCP命令,以在客户端系统中执行SFTP。但是,此代码无法正常工作。您能告诉我什么是正确的方法,因为我相信我做错了。

我正在为python 2.7解释器编写此脚本。

import os
import time
year = time.strftime("%Y", time.localtime())
month = time.strftime("%m", time.localtime())
day = int(time.strftime("%d", time.localtime()))-1
WINSCP =r'"C:\Program Files (x86)\WinSCP\WinSCP.com"'
command = WINSCP + " /console /script=SFTP.txt /parameter /opt/outgoing/ttaftp/" + str(year) + str(month) + str(day) +
       ".zip.pgp C:\Users\m\Desktop\"
os.system(command)

此脚本帮助我执行WinScp命令并获得所需的结果。

最新更新