Error quoting spaces to locate destination filepath WinSCP script issue

邮差的信 提交于 2019-12-01 10:36:33

问题


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"\Dropbox\joebloggs\Data\"System Data"\"Raw Feeds"\Stock\May\

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)\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%

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:\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

回答1:


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:\Users\John Smith\Dropbox\joebloggs\Data\System Data\...\""" ^

(path shortened so that it fits in view)

See WinSCP documentation on command-line syntax.



来源:https://stackoverflow.com/questions/37254538/error-quoting-spaces-to-locate-destination-filepath-winscp-script-issue

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