Running a script with winscp

AlHal2 used Ask the Experts™
I've downloaded WinScp and can see the remote server on the right.
I've written the file below.  When I try to execute it like this it fails.

winscp.exe /console /script=example.txt

option batch on
option confirm off
open userID:PWD@Server
cd /TheDirectory
option transfer binary
get TheFile.txt C:\

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Meir RivkinFull stack Software Engineer

are you sure this is correct: userID:PWD@Server
Winscp cannot start or start connect and get error ?
Can you connect from GUI winscp ? any firewall ?


The GUI works, but in the console session I get an error message
"'winscp.exe' is not recognized as an internal or external command,"
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

where you run command  ? in winscp folder ? try with full path to winscp.exe file:
c:\path\winscp.exe /console /script=example.txt


How do I change directory.  I think the default directory is a\b\c.  I want to go to a\b\d ie a parallel directory.  cd\d doesn't work.
can you post same example ?


Not really as I don't want to paste actual server or directory names.
Would you be able to write a script that connects, changes directory, downloads a file to the c drive and disconnects?
I'll try to use that as a template.
you dont have problem with script "example.txt". The proble is how you start winscp.exe. If you dont start winscp from dicectory where winscp is located, you must use full path: c:\directory\directory_where_is_winscp\winscp.exe /console /script=example.txt
If you use script to start winscp (powershell, vbs) you must type full path to winscp in this script.


I've managed to start winscp.  However when the script comes to the part that changes the directory it fails.


I've figured that bit out.  Now how do I do something like this?  I had a cd.. in the file.

mdel xxx.*.*.*.2010-04-08-*.*.*.*>>%FTPSCRIPT%

In other words I want to delete certain types of files from the server.


The files I want to delete are those where last modified date is more than 3 weeks ago. The 2010-04-08 does not correspond to the modified date.

I also want to run this automatically.


Using the full path worked.  I'll ask the next part of my question in a separate thread.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial