WinSCP批处理脚本,用于从多个IPv6主机下载多个文件

时间:2017-09-07 15:22:03

标签: batch-file ftp winscp

有人请帮助创建一个脚本文件,以便从我的Windows Server 2008 R2 Enterprise执行。

我有一个主机列表,其中IPv6地址为[X25:F0:B2:F314::02][X25:F1:B2:F914::56]等,如25个主机。从每个主机我需要下载300个文件revenue.xmlprodcut_growth.xmlloss.xml .....所以这样。在为每个文件下载时,我想附加日期和时间,因此文件将保存为revenue_07_09_2017.xml

我按照以下程序尝试但未通过:

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

我尝试执行上面的批处理文件但没有帮助。 请提出一些建议。非常感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您可以使用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

(虽然您还希望修改主机的目标路径,否则文件会相互覆盖)

另一种选择是使用Parametrized WinSCP script