我创建了以下名称为的命令文件submitCmd.txt:
submitCmd.txt
open myname@ftpclients.myserve.com -privatekey=C:\Users\Mike\Desktop\uploader\mykey.ppk put C:\Users\Mike\Desktop\uploader\files2Upload\myFile.xlsx /mnt/data/myFolder/ close exit
当我从命令行运行上述脚本时:
winscp.com /script=C:\Users\Mike\Desktop\uploader\submitCmd.txt
它运行成功。
但是,当我在python中尝试以下操作时:
cmdFile = r'C:\Users\Mike\Desktop\uploader\submitCmd.txt' import subprocess subprocess.run(["winscp.com", "/script=", cmdFile], shell=True)
我得到错误:
Searching for host... Host "C" does not exist. winscp>
您的命令将像这样运行WinSCP:
winscp.com /script= C:\Users\Mike\Desktop\uploader\submitCmd.txt
什么是无效的语法。/script=。之后不能有空格。
/script=
这应该工作:
subprocess.run(["winscp.com", "/script=" + cmdFile], shell=True)