我似乎无法使用WinSCP获得有效的同步脚本

时间:2015-11-12 20:11:00

标签: batch-file sftp winscp

我尝试了很多不同的示例脚本,但似乎没有一个适合我。有人可以帮我解决问题吗?

最近的尝试,直接来自示例脚本:

蝙蝠:

winscp.com /script=script.txt /parameter // %1 "/internet/remotedirectory/%~n1%~x1"

TXT:

open sftp://user:pword@sftp.address.gov -hostkey="ssh-rsa 1024 9c:b7:21:5c:ad:02:bb:30:c5:27:a5:bc:41:1a:ab:a0"
synchronize remote "%1%" "%2%"

我运行此bat文件,窗口关闭:使用预先输入的密码进行身份验证。

我真正想要做的是将本地文件夹同步到远程文件夹,但为了学习,我只是想让任何脚本工作。

以前,我曾尝试过:

option batch abort
option confirm off
open sftp://user:pword@sftp.address.gov -hostkey="ssh-rsa 1024 9c:b7:21:5c:ad:02:bb:30:c5:27:a5:bc:41:1a:ab:a0"
synchronize local H:\LocalDirectory /internet/remotedirectory
exit

cmd窗口显示:

Searching for host...
Connecting to host...
Authenticating...
Using username "user".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Session started.
Active session: [1] user@sftp.address.gov
Comparing...
Local 'internet/remotedirectory/' => Remote '%2%'
Error listing directory 'internet/remotedirectory/'.
Error retrieving file list for "internet/remotedirectory/\*.*".
System Error.  Code: 3.
The system cannot find the path specified
(A)bort, (R)etry, (S)kip: Abort
Error listing directory 'internet/remotedirectory/'.
Error retrieving file list for "internet/remotedirectory/\*.*".
System Error.  Code: 3.
The system cannot find the path specified

C:\Program Files (x86)\WinSCP>winscp.com /log=C:\Program Files (x86)\WinSCP\winscp.log /loglevel=2*
Opening session using command-line parameter in scripting is deprecated. Use 'open' command instead.
Searching for host...
Host "Files" does not exist.
winscp>

修改

我添加了本地目录以传递给脚本(%2%):

open sftp://user:pword@sftp.address.gov -hostkey="ssh-rsa 1024 9c:b7:21:5c:ad:02:bb:30:c5:27:a5:bc:41:1a:ab:a0"
synchronize remote "%2%" "%1%"

蝙蝠:

winscp.com /script=script.txt /parameter // %1 "internet/airpoll/out/%~n1%~x1" %2 "H:\APC\TSV\Airnow Queries\%~n1%~x1" 
winscp.com /log="C:\Users\me\Desktop\winscp.log" /loglevel=2*

Cmd窗口显示

C:\Program Files (x86)\WinSCP>winscp.com /script=script.txt /parameter //  "internet/remotedirectory/"  "H:\localdirectory\"
Searching for host...
Connecting to host...
Authenticating...
Using username "user".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Session started.
Active session: [1] user@sftp.address.gov
Comparing...
Local 'H:\localdirectory' => Remote 'internet/remotedirectory'
Error listing directory 'internet/remotedirectory'.
No such file or directory.
Error code: 2
Error message from server: No such file
(A)bort, (R)etry, (S)kip: Abort

C:\Program Files (x86)\WinSCP>winscp.com /log="C:\Users\me\Desktop\winscp.log" /loglevel=2*
winscp>

我不知道为什么它说'没有这样的目录'目录是root / internet / remotedirectory,这就是它在WinSCP客户端中的显示方式。

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

pythonscript.py

只有一个参数C:\Program Files (x86)\WinSCP>winscp.com /script=script.txt /parameter // "internet/remotedirectory" 。虽然脚本需要两个参数。

您似乎没有将任何参数传递给批处理文件。因此批处理文件中的internet/remotedirectory解析为空字符串。