Running WinSCP command from Python

与世无争的帅哥 提交于 2019-12-18 07:12:27

问题


I have created the following command file with name 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

When I run the above script from command line as:

winscp.com /script=C:\Users\Mike\Desktop\uploader\submitCmd.txt

It runs successfully.

However, when I try the following in python:

cmdFile = r'C:\Users\Mike\Desktop\uploader\submitCmd.txt'
import subprocess
subprocess.run(["winscp.com", "/script=", cmdFile], shell=True)

I get the error:

Searching for host...
Host "C" does not exist.
winscp> 

回答1:


Your command will run WinSCP like this:

winscp.com /script= C:\Users\Mike\Desktop\uploader\submitCmd.txt

What is an invalid syntax. There cannot be the space after the /script=.

This should work:

subprocess.run(["winscp.com", "/script=" + cmdFile], shell=True)


来源:https://stackoverflow.com/questions/53066584/running-winscp-command-from-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!