Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

TerryP

Help with scripting (use of variables and download)

WinSCP Version: 4.3.5, Build 1463
Windows version: XP SP3
Transfer Protocol: SFTP (SCP)
Method: Scripting Automation (command line)

Question(s): I am brand new to WinSCP and want to automate a download from each of 500 folders on the server. Is there a way to use variables within WinSCP (no Java/VB/etc.) so I can do a move and rename? Example: I'm downloading files from folder \Project\User and I want to rename the files with <User> as a prefix. So file 100.txt would become BillyB100.txt, file 101.txt becomes BillyB101.txt and so on. I'd like to use a common incoming data folder and eliminate the respective user folders (see below).

Or if the only way to do this is with Java, can anyone provide some sample code? I don't know what exactly can be loaded (or how long it would take to clear) because it is a secured computer.

The script text I have is a long one - each folder is represented - so I won't post the whole thing here. Currently, I am doing a get and then handling the rename on the PC side.

Command line: "c:\program files\WinSCP\WinSCP.com" /script=C:\MyScript.txt /log=C:\SCPTest\MyLog.txt

Contents of MyScript:

# Automatically abort script on errors
option batch on
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect using a password
# Connect
open daemon@Site.company.com
# Force binary mode transfer
option transfer binary
# Change remote directory and Download files
get /Distribution/Project/BillyB/*.* C:\IncomingData\BillyB\
get /Distribution/Project/BillyC/*.* C:\IncomingData\BillyC\
get /Distribution/Project/BobbyA/*.* C:\IncomingData\BobbyA\
get /Distribution/Project/BobbyB/*.* C:\IncomingData\bobbyB\
get /Distribution/Project/JackieA/*.* C:\IncomingData\JackieA\
get /Distribution/Project/JackieB/*.* C:\IncomingData\JackieB\
get /Distribution/Project/Warren/*.* C:\IncomingData\Warren\
get /Distribution/Project/Zeke/*.* C:\IncomingData\Zeke\
# Disconnect
close
# Exit WinSCP
exit

Thanks,
Terry