This is an old revision of the document!

Useful Scripts

Downloading file to timestamped-filename

Using local-side scripting

You can use any available scripting language you have on the local host to appropriate generate WinSCP script. Following example uses PHP language:

get /home/user/examplefile.txt *.<?=date("YmdHis")?>.txt
exit

Advertisement

Execute the script and store the results into temporary script file. The generated script file will look like:

get /home/user/examplefile.txt *.20060605090825.txt
exit

Now pass the generated script file to WinSCP. You can automate all these steps using simple batch file:

php -q download.php > "%temp%\download.tmp"
winscp3 user@example.com /console /script="%temp%\download.tmp"
del "%temp%\download.tmp"

Using remote-side scripting

If you do not have a scripting language on the local host, you can use remote-side script (like shell script). This approach requires opening separate shell session to invoke remote-side scripting:

# Make copy of the remote file to temporary timestamped file
# Also add unique extension to easily find the file in the temporary directory.
call cp /home/user/examplefile.txt /tmp/examplefile.`date +%Y%m%d%H%M%S`.unique
# Download all the files with the unique extension. There should be only one, the one just created.
# While downloading, remove the unique extension.
get /tmp/*.unique *.
# Remove the temporary file.
rm /tmp/*.unique
exit

Advertisement

Last modified: by martin