Link to home
Start Free TrialLog in
Avatar of ApplePiet
ApplePiet

asked on

How to download files from Secure FTP (SFTP)

Good day experts,

I need to automate the downloading of files from an SFTP location.  I have the SFTP host name and folder location to poll for new files.

My workflow basically need to be:
Connect to SFTP and browse the specified folder
Download each file to a local folder
For each successful download, delete or move the original file on SFTP

This process will be executed several times per day.

Please assist / recommend the easiest way to implement this.  I have basic skills in SSIS and C# but neither offer native support for SFTP operations.

Many thanks
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

I use a library from XCeed: http://xceed.com/SFTP_NET_Intro.html
Avatar of ApplePiet
ApplePiet

ASKER

Just started using this one:   http://sshnet.codeplex.com/

Got some of the basics to work so far but it's going slowly - the documentation is good but there are no examples I can find.
Hi

Maybe i am completely offtopic but why not create a batch file that runs (WIN)SCP which is scheduled a few times a day?
@Patricksr1972

Thanks - that did cross my mind but I tend to stick what I know best.  I thought that I would be better off with either SSIS or a custom C# application.

I looked at a few WinSCP examples but I couldn't really figure them out.

With C# i have the capability of easy error handling and writing log data back to SQL Server or a windows event log.

If you think WinSCP can work easily as well, you're welcome to point me to site, resource or example and I'll look into it and compare with what I'm currently doing.

Thanks
Cool, let me login to one off the servers i have configured for running like this and i get back to you...
@Éric Moreau

Exceed looks good but it's somewhat expensive though.   Our project did not budget for purchasing components like this.  Our sales team expected to be able to integrate with FTP using native .Net.  They did not consider SFTP.

With the exchange rate, required license for exceed will cost our project in the region of  ZAR 25000.

I will need to look at something less expensive.  

Exceed definitely looks good for future projects though.

Thank you
Ok,

So i have got a (scheduled) batch file with this content:

winscp.exe /script=script.txt

In the script i run this:

option batch on
option confirm off
open SFTPACCOUNTNAME@<ipadress>:22 -privatekey=PrivKey.ppk
option transfer binary
get file-<filename> c:\put-the-files-here\
close
exit



Then, from the batch OR the script you can add copy/move commands to transfer your files where desired.
HTH
@Patricksr1972:

Wow that actually quite ....    short.

Let me try that out also.   I actually logged on now to report that my solution now works (will post that now).

What is the private key in your script?

Thanks again
ASKER CERTIFIED SOLUTION
Avatar of ApplePiet
ApplePiet

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
Hi, the ppk contains your private key which you generate and save as <ftpsaccountname>.ppk.
Worked best