WinSCP batch script to download multiple files fro

2019-06-05 02:51发布

问题:

Someone please help to create a script file to simply execute from my Windows Server 2008 R2 Enterprise.

I have a list of of host with IPv6 address as [X25:F0:B2:F314::02], [X25:F1:B2:F914::56] so on, like 25 hosts. And from each host I need to download 300 files revenue.xml, prodcut_growth.xml, loss.xml..... so on like this. While downloading for each file I want to append date and time so file will be saved as revenue_07_09_2017.xml.

I tried by following procedure but failed:

cd "c:\Program Files\WinSCP"
winscp.com /command "open user:password@[X25:F0:B2:F314::02]" get "/home/user/revenue.xml" "C:\downloaded\revenue.xml.%TIMESTAMP#yyyymmddhhnnss%"
get "/home/user/loss.xml" "C:\downloaded\loss.xml.%TIMESTAMP#yyyymmddhhnnss%""exit"
#Second host starts here
winscp.com /command "open user:password@[X25:F1:B2:F914::56]" get "/home/user/revenue.xml" "C:\downloaded\revenue.xml.%TIMESTAMP#yyyymmddhhnnss%"
get "/home/user/loss.xml" "C:\downloaded\loss.xml.%TIMESTAMP#yyyymmddhhnnss%""exit"
exit

I tried to execute above batch file but not helped. Please suggest some approach. Your help is highly appreciated.

回答1:

You can use a batch file with a sub routines:

@echo off

call :download [X25:F0:B2:F314::02]
call :download [X25:F1:B2:F914::56]
call :download ...

exit /b

:download
echo open ftp://username:password@%1/ > script.tmp

call :addfile revenue.xml
call :addfile loss.xml
call :addfile ...

echo exit >> script.tmp
"C:\Program Files (x86)\WinSCP\winscp.com" /script=script.tmp
del script.tmp
exit /b

:addfile
echo get "/home/user/%1" "C:\downloaded\%1.%%TIMESTAMP#yyyymmddhhnnss%%" >> script.tmp
exit /b

(though you will also want to modify the target path with the host, as otherwise the files will overwrite one another)


Another option is to use Parametrized WinSCP script.