WinSCP, command line SFTP and automation

I had a co-worker ask me about using WinSCP for automating SFTP puts to a remote host.    I personally have never setup a SFTP server nor use SFTP client (or it’s been a while :)).   There is a thread on that has great information.   I included the link to the post.  The one thing I used for my test was FreeFTPD, which was real straight forward.  It seems to support NT Authentication.  I tried a couple of times, seems to be lacking a easy feature to extend to an entire Active Directory environment.  For my testing, it was very good.    I setup on Windows Server 2008 R2 with no issues.  I’ve setup FTP over SSL too and it’s a different solution.  Depends on your requirements. 

//Syntax I used on my client to automate. 
//”C:Program” /script:”C:Program FilesWinSCPWinSCP.txt”                                                                          

option batch on
option confirm off
open sftp://SCS:[email protected]:22 -hostkey=”ssh-rsa 1024 42:9e:c7:f4:7f:8b:50:10:6a:06:04:b1:d4:f2:04:6d”
cd /CDrive
put c:Default.htm

//How I got the -hostkey using WinSCP from client
//”C:Program” /command

winscp> help
call     Executes arbitrary remote command
cd       Changes remote working directory
chmod    Changes permissions of remote file
close    Closes session
exit     Closes all sessions and terminates the program
get      Downloads file from remote directory to local directory
help     Displays help
keepuptodate Continuously reflects changes in local directory on remote one
lcd      Changes local working directory
lls      Lists the contents of local directory
ln       Creates remote symbolic link
lpwd     Prints local working directory
ls       Lists the contents of remote directory
mkdir    Creates remote directory
mv       Moves or renames remote file
open     Connects to server
option   Sets or shows value of script options
put      Uploads file from local directory to remote directory
pwd      Prints remote working directory
rm       Removes remote file
rmdir    Removes remote directory
session  Lists connected sessions or selects active session
synchronize Synchronizes remote directory with local one
winscp> open
Host: web1
Searching for host…
Connecting to host…
The server’s host key was not found in the cache. You have no guarantee that the
 server is the computer you think it is.

//This is not a internet facing system.  I just wanted to mention. ?
The server’s rsa2 key fingerprint is:
ssh-rsa 1024 42:9e:c7:f4:7f:8b:50:10:6a:06:04:b1:d4:f2:04:6d
If you trust this host, press Yes. To connect without adding host key to the cac
he, press No. To abandon the connection press Cancel.
Continue connecting and add host key to the cache?
(Y)es, (N)o, C(a)ncel, (C)opy Key: Cancel


Steve Schofield
Microsoft MVP – IIS

2 thoughts on “WinSCP, command line SFTP and automation

  1. Steve,

    I’ve always loved SFTP over FTP-S. It’s great to have good solid solutions for that on a Windows box (although I feel that SFTP is something that should be native to Windows by now).


  2. I have some straight forward WinSCP “Scheduled Tasks” that I need to run every day. I just needed to know the commands and YOU GAVE THEM TO ME.
    Thanks, so much.

    I’ve been all over thw web looking for them and you put it on one page.

    This was a real help.

Comments are closed.