1

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.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Python Spark
  • 303
  • 2
  • 6
  • 16
  • Don't use /command but /script mode generating the script on the fly like described in https://winscp.net/eng/docs/script_upload_file_list#scripting replacing put with get (and the order of arguments) –  Sep 07 '17 at 16:32

1 Answers1

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.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992