错误引用空格以定位目标文件路径 WinSCP 脚本问题
Error quoting spaces to locate destination filepath WinSCP script issue
我编写了一个基本的 .bat
文件脚本,可以通过 WinSCP 自动下载一组文件。我已使用此代码执行按预期工作的类似过程,但绊脚石似乎是目标文件路径。我试过使用
C:\Users\"John Smith"\Dropbox\joebloggs\Data\"System Data"\"Raw Feeds"\Stock\May\
和其他变体,整个文件路径也在引号内。如果有人可以建议输入此文件路径的正确语法,将不胜感激。代码如下:-
@echo off
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\Users\John Smith\Documents\WinSCP.log" /ini=nul ^
/command ^
"open sftp://joebloggs:%%40faNliGHT4@82.121.124.146/ -hostkey=""ssh-rsa 1024 01:01:dd:1c:54:72:98:c7:42:f9:15:8e:30:8c:66:3b"" -passive=0" ^
^
"get "/*.txt" "C:\Users\John Smith\Dropbox\joebloggs\Data\System Data\Raw Feeds\Stock\May\" ^
"exit"
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
echo Error
)
exit /b %WINSCP_RESULT%
错误日志如下:-
> 2016-05-16 13:32:43.902 Access is denied
. 2016-05-16 13:32:43.902 Asking user:
. 2016-05-16 13:32:43.902 Can't create file 'C:\Users\John.filepart'. ("System Error. Code: 5.
> 2016-05-16 13:32:43.902 Access is denied")
< 2016-05-16 13:32:43.902 Script: Can't create file 'C:\Users\John.filepart'.
< 2016-05-16 13:32:43.902 Script: System Error. Code: 5.
> 2016-05-16 13:32:43.902 Access is denied
> 2016-05-16 13:32:43.903 Type: SSH_FXP_CLOSE, Size: 23, Number: 2052
> 2016-05-16 13:32:43.903 (EScpSkipFile) Can't create file 'C:\Users\Daniel.filepart'.
> 2016-05-16 13:32:43.903 System Error. Code: 5.
> 2016-05-16 13:32:43.903 Access is denied
> 2016-05-16 13:32:43.903 Script: Failed
> 2016-05-16 13:32:43.903 Script: Exit code: 1
> 2016-05-16 13:32:43.903 Closing connection.
> 2016-05-16 13:32:43.903 Sending special code: 12
> 2016-05-16 13:32:43.903 Sent EOF message
你必须双引号。您还缺少 get
命令末尾的引号(注意三个连续的引号)。
"get ""/*.txt"" ""C:\Users\John Smith\Dropbox\joebloggs\Data\System Data\...\""" ^
(路径已缩短以适合视图)
见WinSCP documentation on command-line syntax and FAQ Why are some WinSCP scripting commands specified in a batch file not executed/failing?
您还可以 WinSCP GUI generate a SFTP batch file template for you,包括正确的引号。
我编写了一个基本的 .bat
文件脚本,可以通过 WinSCP 自动下载一组文件。我已使用此代码执行按预期工作的类似过程,但绊脚石似乎是目标文件路径。我试过使用
C:\Users\"John Smith"\Dropbox\joebloggs\Data\"System Data"\"Raw Feeds"\Stock\May\
和其他变体,整个文件路径也在引号内。如果有人可以建议输入此文件路径的正确语法,将不胜感激。代码如下:-
@echo off
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
/log="C:\Users\John Smith\Documents\WinSCP.log" /ini=nul ^
/command ^
"open sftp://joebloggs:%%40faNliGHT4@82.121.124.146/ -hostkey=""ssh-rsa 1024 01:01:dd:1c:54:72:98:c7:42:f9:15:8e:30:8c:66:3b"" -passive=0" ^
^
"get "/*.txt" "C:\Users\John Smith\Dropbox\joebloggs\Data\System Data\Raw Feeds\Stock\May\" ^
"exit"
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
echo Error
)
exit /b %WINSCP_RESULT%
错误日志如下:-
> 2016-05-16 13:32:43.902 Access is denied
. 2016-05-16 13:32:43.902 Asking user:
. 2016-05-16 13:32:43.902 Can't create file 'C:\Users\John.filepart'. ("System Error. Code: 5.
> 2016-05-16 13:32:43.902 Access is denied")
< 2016-05-16 13:32:43.902 Script: Can't create file 'C:\Users\John.filepart'.
< 2016-05-16 13:32:43.902 Script: System Error. Code: 5.
> 2016-05-16 13:32:43.902 Access is denied
> 2016-05-16 13:32:43.903 Type: SSH_FXP_CLOSE, Size: 23, Number: 2052
> 2016-05-16 13:32:43.903 (EScpSkipFile) Can't create file 'C:\Users\Daniel.filepart'.
> 2016-05-16 13:32:43.903 System Error. Code: 5.
> 2016-05-16 13:32:43.903 Access is denied
> 2016-05-16 13:32:43.903 Script: Failed
> 2016-05-16 13:32:43.903 Script: Exit code: 1
> 2016-05-16 13:32:43.903 Closing connection.
> 2016-05-16 13:32:43.903 Sending special code: 12
> 2016-05-16 13:32:43.903 Sent EOF message
你必须双引号。您还缺少 get
命令末尾的引号(注意三个连续的引号)。
"get ""/*.txt"" ""C:\Users\John Smith\Dropbox\joebloggs\Data\System Data\...\""" ^
(路径已缩短以适合视图)
见WinSCP documentation on command-line syntax and FAQ Why are some WinSCP scripting commands specified in a batch file not executed/failing?
您还可以 WinSCP GUI generate a SFTP batch file template for you,包括正确的引号。