Link to home
Start Free TrialLog in
Avatar of First Last
First LastFlag for United States of America

asked on

Scripting SFTP file transfer

Hello experts - I don't have much experience with scripting and have been asked to create one to transfer files over a SFTP connection to a local drive on a windows server, rename the files, then alert me when the task completes.  I've tested the connection which works fine using WinSCP.  There is a scripting function within the application but I don't know if that's the best way to approach this.  If it could be done via the command line perhaps that is a better option.  Please let me know what you have any ideas  about how to complete the task, syntax help greatly appreciated!
Avatar of Bill Prew
Bill Prew

There are a number of ways you could approach this.  If you want a fairly easy solution you might want to invest in RoboFTP.  It's not free, but the scripting language is quite robust and there are some good experts here that know it well.

http://www.robo-ftp.com/

You can accomplish this with WinSCP as well, but you will have to work a little harder I believe.  I think there are a couple of approaches there.  You can drive the process from a BAT script file, and use the older text command script file approach of WinSCP to execute the steps needed for the transfer and rename, etc.  You won't be able to email from WinSCP though, and from a BAT file to send email you need something like the free BLAT tool. There are many examples of using BLAT from a BAT script here on EE that you can search for.

http://winscp.net/eng/docs/scripting#using_scripting
http://www.blat.net/

In addition, WinSCP supports a newer type of scripting which is more powerful, but a bit more complicated.  But it might allow you to do the file transfer from the control of say a VBS script, and then also send an email from the VBS script after the transfer is done.

http://winscp.net/eng/docs/library_com_wsh#vbscript

~bp
Avatar of First Last

ASKER

Ok, I read through a bunch of that and I think this can be done easily enough with WinSCP for free.  I just need some help with the syntax.  So there are two files I need to move from this SFTP site once a day.  I was thinking using a scheduled task to call winscp.com with something like these parameters might work:

winscp.com /command "option batch abort" "option confirm off" "open SFTPsite.net" "get examplefile.txt /home/user/" "exit"

But I'm missing info there.  I need to pass a username/password and specify a particular directory to copy the files to.  I can worry about renaming them with another script later.  Any ideas on what the proper syntax would be to authenticate and for the directory?
SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Awe, you were holding out Dan, had some .Net skills hiding back there I see :-).

~bp
:)  Wish I could take credit, I grabbed some sample code and filled in the blanks!
Best solution
Thanks.

~bp