Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am pretty new at WinSCP. I would like to know if this application will allow me to send only the latest modified file in a local directory to a remote directory. Please note that contents in both folders do not match at any given time - thus, synching is not an option.

I have managed to establish connectivity and "put" a file onto the server. However, I am not able to figure out how I can achieve what I want to achieve.

Here are my commands...

winscp.exe /console /command "option batch on" "open ftp://user:pass@remoteip:port -explicitssl -passive" "put c:\files\Completed /Test" "exit" /log=c:\winscp_log.txt

Any help is greatly appreciated...

share|improve this question
See WinSCP sample Uploading the most recent file. – Martin Prikryl Jul 19 at 8:25

1 Answer 1

up vote 2 down vote accepted

You won't be able to do that using WinScp by itself. It's scripts aren't that complex. You'll have to use another scripting language to get the latest file.

For example this batch file:

@echo off

for /f "delims=" %%i in ('dir /b /od c:\files\Completed\*') do set LastFile=%%i

winscp.exe /console /command "option batch on" "open ftp://user:pass@remoteip:port  -explicitssl -passive" "put c:\files\Completed\%LastFile% /Test" "exit" /log=c:\winscp_log.txt
share|improve this answer
@shf301 - hi, this is a very useful tip to know. At the moment, I believe it is doing exactly what it is meant to do. However, the LastFile variable does not seem to capture the entire filename if it contains spaces? Excuse my ignorance but how do i modify it to capture the spaces in the filename? The winscp log error states "The system cannot find the file specified "c:\files\Completed\Copy" but the actual filename is "c:\files\Completed\Copy of text.txt" Appreciate it if you could show me how to manipulate the "for" line – molecule Jun 30 '10 at 6:36
I've updated my answer. By default for will split on spaces, the setting the delimiters to nothing ("delims=") it will not break the file name up. – shf301 Jun 30 '10 at 23:54
@shf301 - thanks so much. This worked exactly as how I wanted it set up. Appreciate your help. If it is not too much to ask, I have another scripting problem I would like your assistance on if possible. I don't want to be rude and paste it here before I asked if you were willing to take a look :) Please let me know. Thanks! – molecule Jul 2 '10 at 1:23
@shf301 - excuse my ignorance but what does the %%i do? when i remove @echo off, I actually see that it is passing %i. Reason i'm asking, when i try the script on a different machine, the for loop doesn't keep the filename as how it worked on my PC. the "for" still looks like it splits the spaces and can't recognise them. – molecule Jul 7 '10 at 23:30
The %%i is the variable. Variables in batch files always start with a %. The batch process strips one off, so the for loop only sees a single %. I'm not sure why it isn't working though. – shf301 Jul 8 '10 at 3:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.