Link to home
Start Free TrialLog in
Avatar of rwheeler23
rwheeler23Flag for United States of America

asked on

Using C# to copy files from an SFTP server.

I need to create an C# application and I have two questions.

1) Can it be setup to point to an SFTP server, log in with the credentials and start the file transfer?

2) I have two files to transfer each day. One with have the prefix 'HMSV' and the other will be 'HMPO'. I need the most recent version of each of these files.


I am looking for guidance as to how to set this up. Any advice and/or links would be greatly appreciated.

Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Yes. The SSH.NET library will handle SFTP transfers very, very easily. Should handle 99% of what you're asking for.

GitHub - sshnet/SSH.NET: SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism. 

hi,
you can with c#,
can i please make suggestion... you can use winSCP.
i has a command line option and very easy to set up.
https://winscp.net/eng/docs/commandline

Avatar of rwheeler23

ASKER

Will it be able to filter on those twp file types and grab only the most recent?
If you're asking if the SSH.NET library could filter, then yes. It provides a mechanism to list files, and you can use that to find the most recent files and download them.

If you're asking about WinSCP, that depends on if the filenames are different each time. WinSCP has a synchronize feature that (among other things) can keep a file on your computer in sync with what's remote based on something like last modification time. But if the filenames are different each time, you'd have to get into scripting anyway. Or if you're open to keeping a folder on your PC in sync with the remote folder, that synchronize feature could do that, too. You'd end up with all the files in the folder instead of just the recent files, but it would be able to skip over files that you have.
I am try to keep two separate ERP solutions in sync. Each day new orders are placed in ERP#1, At 5pm they are dumping an export file onto the SFTP server. Each file will be suffixed with the days date. This is why I need to search using the file prefix and then download the most recent version. Once downloaded this csv file will be loaded into ERP#2.C# will be used as the code to perform the actual import resides in there.
ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

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
I completely agree. My C# contains a toolkit to import the transactions so this needs to be done with C#. I have downloaded SSH.NET-2020.0.1.zip and will get this installed.