WinSCP won't execute the entire script specified on a command-line

核能气质少年 提交于 2020-01-02 20:20:21

问题


My very first post but before coming here I did a research on the issues I have. Mostly on WinSCP forums but it came to no fruition.

Using winscp.com, I would like a script to use get command to download multiple files using SFTP. Here is my version:

echo ENTER WEEK NUMBER

set /p input=""

cls

Rem Create folder based on date

set year=%date:~6,4%


mkdir \\11.111.111.11\Folder1\"Folder 2"\#Folder3\%year%_WK%input%

mkdir \\11.111.111.11\Folder1\"Folder 2"\#Folder3\%year%_WK%input%\User_1

mkdir \\11.111.111.11\Folder1\"Folder 2"\#Folder3\%year%_WK%input%\User_2

mkdir \\11.111.111.11\Folder1\"Folder 2"\#Folder3\%year%_WK%input%\User_3

c:

cd Program Files (x86)

cd Winscp

WinSCP.com /command ^

        "#echo off" ^

        "# Connect to server"^

        "Open sftp://Uname:pass@999.999.999.999" ^

        "# batch off mode" ^

        "option batch off" ^

        "lcd \\11.111.111.11\Folder1\""Folder 2""\#BFolder3\%year%_WK%input%\User_3" ^

        "cd .."^

        "cd RemoteFolder/USer_Folder" ^

        "get %year%WK%input%.zip"^

        "cd .."^ 

        "cd User_2_Folder" ^

        "get User2WK%input%.csv"^

        "get SAV_LACWK%input%.csv"^

Issue is, the WinSCP executes cd .. after the first get command and it just stops. It won't go any further:

If I copy/paste at the command prompt, it works fine.

Any idea?

Thank you Donne


回答1:


  1. All your absolute local paths use a wrong syntax C\: for a drive. The correct syntax is C:\.

    mkdir C\:%year%Folder\
    mkdir C\:%year%Folder\Data_User
    ...
    
    WinSCP.com /command ^
        ....
        "lcd C\:%year%Folder\Data_User" ^
    
  2. You are missing a quote and an escape character (^) after

        “# Change remote directory
    
  3. You are using fancy quotes ( and ), instead of the plain double-quotes (") in:

        “#Set local directory”^
        ....
        “# Change remote directory
    
  4. You have a space after the ^ in

    "cd .."^ 
    

    This effectively makes the ^ be ignored (it escapes the space, not the newline).

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


If this does not help, we need to see the output of the batch file run (ideally with removed @echo off).




回答2:


you're missing both the double quote and ^ at the end of the line before

change this:

“# Change remote directory

to:

"# Change remote directory" ^


来源:https://stackoverflow.com/questions/34162875/winscp-wont-execute-the-entire-script-specified-on-a-command-line

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