Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
721 views
in Technique[技术] by (71.8m points)

batch file - Error quoting spaces to locate destination filepath WinSCP script issue

I've written a basic .bat file script that automates downloading a group of files via WinSCP. I have used this code for performing a similar process which is working as intended, however the stumbling block appears to be the destination filepath. I have tried using

C:Users"John Smith"DropboxjoebloggsData"System Data""Raw Feeds"StockMay

and other variations with the whole filepath within inverted commas also. If anyone could advise the correct syntax for entering this filepath it would be appreciated. Code is as follows:-

@echo off
"C:Program Files (x86)WinSCPWinSCP.com" ^
  /log="C:UsersJohn SmithDocumentsWinSCP.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:UsersJohn SmithDropboxjoebloggsDataSystem DataRaw FeedsStockMay" ^
    "exit"

set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)

exit /b %WINSCP_RESULT%

Error Log is as follows:-

> 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:UsersJohn.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:UsersJohn.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:UsersDaniel.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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your have to double the double quotes. You are also missing a quote at the end of the get command (note the three consecutive quotes).

"get ""/*.txt"" ""C:UsersJohn SmithDropboxjoebloggsDataSystem Data...""" ^

(path shortened so that it fits in view)

See WinSCP documentation on command-line syntax and FAQ Why are some WinSCP scripting commands specified in a batch file not executed/failing?


You can also have WinSCP GUI generate a SFTP batch file template for you, including correct quotes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...