tags:

views:

557

answers:

5

Hi,

I've written a service for our customer that automatically transmits files to given destinations using FTP. For historic reasons I'm using WinInet to perform the FTPing. All works well, but now the customer wants to add one destination that only accepts SFTP connections.

I do not really like the idea of implementing this from scratch, so is there a way to communicate natively or through WinInet with a SFTP server? Are there any system libraries that I can use (I have no fear of P/Invoke :) )? Do I have to purchase third party components for that - if so, which ones would you suggest?

Thanks,
Thorsten

+2  A: 

http://sourceforge.net/projects/sharpssh/ could be your best best. I ended up writing scripts for WinSCP though, which was easier...

davewasthere
Have also heard good things about http://www.enterprisedt.com/products/edtftpnetpro/overview.html, but not actually used it.
davewasthere
I've used it and love it. Would recommend it without hesitation.
Walter
Seconding @Walter's claim. This is a great library.
mrduclaw
+2  A: 

Unfortunately, SFTP is not natively supported by WinInet or any other standard Windows libraries.

I've had good luck with /n Software's IP*Works SSH for .NET in talking to a large variety of SFTP servers.

mdb
A: 

Either you install some sftp executables , and call them from your c# program to perform the operaton, much like you would do manually on the command line, or use a library such as SharpSSH

nos
Well, the customer needs most exact logging, so just invoking some tool is not desired. However, I'll try SharpSSH.
Thorsten Dittmar
A: 

I use edtFTPnet/PRO

http://www.enterprisedt.com/products/edtftpnetpro/overview.html

works great

quimbo
A: 

Hi,

the .NET Framwork supports FTP via the FtpWebRequest since version 2.0. No support for SFTP yet.

If you need both FTP and SFTP you have to try a third party component. There is an open source implementation of SFTP from Tamir Gal which is often recommended. Or you can try one of commercial SFTP components such as our Rebex SFTP.

Following code is taken from Rebex SFTP tutorial page:

// create client, connect and log in 
Sftp client = new Sftp();
client.Connect(hostname);
client.Login(username, password);

// upload the content of 'c:\data' directory and all subdirectories 
// to the '/wwwroot' directory at the server 
client.PutFiles(@"c:\data\*", "/wwwroot", SftpBatchTransferOptions.Recursive);

client.Disconnect();

If you are not sure whether you will need FTPS or SFTP you can check the Rebex File Transfer Pack which includes both. The FTP API is almost identical to the SFTP one.

Martin Vobr