Answered by:
SSH/SFTP Communications in C#
Question
-
I'm looking to get started implementing a SFTP handler in my application (.net 2.0) and so far I'm just not finding what I'm looking for. Seems like all the SSH/SFTP code and libraries out there are for the Linux crowd.
Can anyone point me in the right direction? Am I going to be making calls to a command-line SSH app, or is this something that's going to be doable with reasonable effort?Saturday, September 24, 2005 8:12 PM
Answers
-
Microsoft does not provide thouse in-box.
You need to search for third-party one.
For example for SSH you can try this OpenSource http://www.routrek.co.jp/en/product/varaterm/granados.html as well there are a lot of others commertial vendors.
Sunday, September 25, 2005 2:55 AM
All replies
-
SSL/FTP is already supported in System.Net 2.0
You can also use Sockets/NetworkStream
and then compose an SSLStream on top of the NetworkSteam.
That way you don't need to worry about the SSL implementation- Proposed as answer by Mehmood Ahmed Tuesday, September 7, 2010 11:08 AM
Saturday, September 24, 2005 9:42 PMModerator -
SSH is not SSL, and SFTP is not FTP over SSL.Sunday, September 25, 2005 1:45 AM
-
I don't believe .NET supports ssh natively ... Mono does, but I think these were added specifically for linux.
http://www.jscape.com/articles/sftp_using_csharp.html
appears to be what you'd be looking for. There are other commercial .NET packages for ssh as well.
JoshSunday, September 25, 2005 2:54 AMModerator -
Microsoft does not provide thouse in-box.
You need to search for third-party one.
For example for SSH you can try this OpenSource http://www.routrek.co.jp/en/product/varaterm/granados.html as well there are a lot of others commertial vendors.
Sunday, September 25, 2005 2:55 AM -
thanks TAG I hadn't seen that one before, I'll look into it.Sunday, September 25, 2005 10:01 PM
-
Hi,
Recently I ported some of the JSch java SSH lib to C#. I posted my code at the codeproject website: http://www.codeproject.com/useritems/sharpSsh.asp.
The demo project contains an examples directory that also contains an SFPT implementation.- Proposed as answer by jeganinfo Thursday, July 30, 2009 1:13 PM
Monday, October 17, 2005 1:26 PM -
http://www.tamirgal.com/home/dev.aspx?Item=sharpSsh
Is another link to this project. I just tested it and it works great for transfering SFTP files.Wednesday, December 7, 2005 7:23 PM -
Hi Tamir
I'm wanting to transfer files over sftp in from an asp.net website to an sftp server. Will your classes adapt for this task? ie. Running in a remote host envirmonment as opposed to a windows app environment?
Any advice much appreciated.
Cheers.
Monday, November 6, 2006 11:53 PM -
TAG wrote: You need to search for third-party one.
For example for SSH you can try this OpenSource http://www.routrek.co.jp/en/product/varaterm/granados.html as well there are a lot of others commertial vendors.
This product (Granados) is SSH only, not SFTP. Anyone wanting to implement SFTP should consider extending Granados. (1) A combined SSH/SFTP product is far more useful than either one alone because the user does not need to learn two totally different ways to interface into these related protocols. (2) A lot of the functionality (such as all the crypto) is already there and you can focus on producing the file transfer functionality.
Monday, February 19, 2007 3:46 PM -
Scott C. Reynolds wrote: I'm looking to get started implementing a SFTP handler in my application (.net 2.0) and so far I'm just not finding what I'm looking for. Seems like all the SSH/SFTP code and libraries out there are for the Linux crowd.
Can anyone point me in the right direction? Am I going to be making calls to a command-line SSH app, or is this something that's going to be doable with reasonable effort?There's a number of SSH/SFTP solutions for .NET.
You can check the comparison chart at http://www.eldos.com/sbb/sftpcompare.php . See the sample of how to use SFTP with VB.NET on http://www.eldos.com/sbb/sftp.net/sftp-net-vb-sample.php
Sincerely yours,
Eugene Mayevski
Sunday, March 25, 2007 8:37 PM -
Can you direct me to where in Mono ssh is supported natively? I need ssh and maybe scp. I realize I could use one of the other solutions mentioned in this thread, but if it is possible to use Mono's libraries, that would be much more preferable.
Thanks!Tuesday, March 27, 2007 8:20 PM -
Hello Tamir,
I am using your SharpSsh, but it doesn't work with commands for removing files. I tried to do it with SshExec and with SshShell by running a command "rm -f filename.wav", but didn't achieve to get a response. The command starts and never ends... Any idea?
Please answer as soon as possible.
Regards,
L.
I also posted the same question on code project, but nobody answered...Monday, June 11, 2007 8:29 AM -
i tried with the Sharp SSH componet . it works to implementconnection with remote server but while upload/download files i am getting error like "unknown error"
- Proposed as answer by while1 Wednesday, December 14, 2011 3:54 PM
Friday, August 17, 2007 9:30 AM -
Hey Lenka,
I had similar problems trying to use SharpSsh and, so I took a dive into Granados and after some effort I could make it work
.What I do in my app is to connect to a list of servers(one at a time) and execute a series of non-interactive commands(one at a time also), it might be helpfull, are u interested?
Regards,
Tuesday, September 11, 2007 11:36 PM -
Can you please share it? I am looking for FTP over SSH implementation from quite some time.
Thanks,
Friday, September 21, 2007 9:37 PM -
I'm not using SFTP services (as a matter of fact I don't think Gradanos supports SFTP), only SSH to execute commands on a remote unix server. If u are still interested in my code plz let me know and I'll send it you
Regards
Friday, September 21, 2007 9:59 PM -
Can you please share it? I am working on making a C# SFTP component.... I would like to see how I can use this.
Thanks
Saturday, September 22, 2007 4:08 PM -
Dreico,
I am interested in seeing how you accomplished that with Granados, I'm working on something very similar and got it working in SharpSSH but the connection seems flaky. I'm having trouble getting a grasp on what to do in Granados, any help would be most appreciated.
Thanks,
BrianMonday, September 24, 2007 11:25 PM -
If you're still having trouble, try IPWorks SSH: http://www.nsoftware.com/ipworks/ssh/.
If you have any questions feel free to contact me personally on my blog, I can help. Disclaimer: yes, I work at /n software.
Lance
Wednesday, September 26, 2007 2:04 PM -
Hi Brian,
How can I help you? do you want me to send you my code? If so, plz post your email address and I'll do it.
Regards
Wednesday, September 26, 2007 2:10 PM -
.Net 2.0 only supports download for FTPS (aka FTP over SSL).
If you try to issue, for example, the Upload command, you will get a not supported issue.
It also has limitations regarding proxies.
Saturday, December 29, 2007 12:29 AM -
That doesn't make any sense.Saturday, December 29, 2007 2:07 AM
-
Dreico,
Could you please send me your code examples. I'm new to C# (been C/C++ for years) and I'm having trouble wading through the Granados code.
My email address is madwhit@hotmail.com.
Thanks, I really appreciate it.
-Don
<><Friday, January 11, 2008 4:52 PM -
Thursday, January 17, 2008 2:56 AM
-
Cheul,
I found Dreico's code here http://www.msdner.com/dev-archive/219/12-40-2190761.shtm
I can get it to login but I can't seem to get it to issue commands on the server. If I figure something more out I'll post here. Please do the same for me.
Hope this helps,
-Don
<><Thursday, January 17, 2008 8:33 PM -
I am trying to do exactly the samething, did you find any solution to implement SFTP in C#
Tuesday, January 20, 2009 8:24 PM -
Can you please share your code if you got it working ?
Thanks
Tuesday, February 3, 2009 10:42 PM -
Can you please share your code if you got it working ?
Thanks
Tuesday, February 3, 2009 10:43 PM -
Take a look at edtFTPnet/PRO, which is a comprehensive client library supporting SFTP, FTP and FTPS. Loads of features and it's been around for a long time.
Friday, April 24, 2009 4:22 AM -
I have prepared guide to using WinSCP SFTP client from .Net (including C# example). I hope you find it useful.Tuesday, June 2, 2009 7:23 AM
-
-
Tamir:
Your code worked for one host but failed for another. I believe the problem is the second host doesn't allow reading rights in the inbox. They only allow a file to be created and it seems your code creates the file first, checks some stuff, and then writes the data. I need something that just creates the file with all the data in one step. I've been trying to understand how your code works and modify it but after a complete day of working on it, I'm just as clueless as I was when I started. Can you help?Tuesday, December 29, 2009 10:11 PM -
Tamir,
I like to evaluate how your library works. Unfortunately the URL http://www.codeproject.com/useritems/sharpSsh.asp is not working. Thanks.
fafaacomSunday, January 3, 2010 7:25 PM -
Hi,
Can u send me some sample code to read and write image from the serverMonday, January 4, 2010 10:29 AM -
hi,
can u send me the code.
anu1983in@gmail.com
Thanks,
AnuMonday, January 4, 2010 10:31 AM -
Scott,
I just launched a .NET SFTP Library . Please try it out and let me know what you think.
Thanks,
Greg Finzer
Kellerman SoftwareFriday, April 23, 2010 12:37 AM -
Hi,
Please have a look at this .NET API which supports SFTP protocol :
Best Regards,
JSCAPE - Managed File Transfer & Security Solutions http://www.jscape.comTuesday, June 1, 2010 2:15 AM -
Hello,
There are some commercial and free tools. A commercial one is at this SFTP lib web page , this blog post . If someone loves FREE tool, try this SFTP library on codeproject.
- Edited by Clark MCPD Saturday, August 18, 2012 11:17 AM update links
Thursday, July 1, 2010 4:50 PM -
It is hard to believe that microsoft does not have SFTP built in.
Here is what I did as an interim solution
Make sure you reference at the top of you VB script
Imports System.IO
I use Putty's psftp which is a stand alone program
Program found here http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
I then write a BATCH file to the users temp files system and execute the batch script all in my vb code as follows...
Hope this helps someone! Only way around not having to load anything and have to pay big $$$ to SFTP a file, however the script is dependent on having Putty's psftp file in place.
Imports System.IO Public Class Form1 Sub GetFile() Dim ftpscript As Integer = FreeFile() Dim tempscriptfile As String = My.Computer.FileSystem.GetTempFileName Dim tempbatfile As String Dim HostName As String = "username@hostname or IP address of SFTP server example: user@123.123.123.123" Dim password As String = "password for your user" FileOpen(ftpscript, tempscriptfile, OpenMode.Output) ' just use the same directory where you want to save your file for the lcd PrintLine(ftpscript, "lcd ""c:\path\to\local\directory""") PrintLine(ftpscript, "cd /remote/directory/") PrintLine(ftpscript, "get filetoget.txt") PrintLine(ftpscript, "bye") FileClose(ftpscript) tempbatfile = My.Computer.FileSystem.GetTempFileName tempbatfile = Mid(tempbatfile, 1, Len(tempbatfile) - 4) & ".bat" FileOpen(ftpscript, tempbatfile, OpenMode.Output) ' Enter the drive where your file will be loaded on the local drive. PrintLine(ftpscript, "C:") ' Change to where you want to save the file on the local drive make sure it is writable by the end user PrintLine(ftpscript, "CD ""c:\path\to\local\directory""")<br/> PrintLine(ftpscript, """C:\path\to\your\psftp\program\psftp.exe"" " & HostName & " -pw " & password & " -b " & """" & tempscriptfile & """") FileClose(ftpscript) Shell(tempbatfile, AppWinStyle.MinimizedNoFocus, True) Kill(tempbatfile) Kill(tempscriptfile) End Sub End Class
Saturday, July 10, 2010 6:55 AM -
It really makes no sense that MS has not added this to .NET! This has been an issue for over 3 years!!!! Buy a company or something. But PLEASE add it.Thursday, July 22, 2010 6:26 PM
-
Hi,
I want to know any commercial library I can use to SCP between two remote hosts. Please let me know.
Regards,
Sundar
- Proposed as answer by StevenRapp ATPBanned Sunday, December 26, 2010 7:40 PM
Monday, November 15, 2010 7:17 AM -
....Or maybe they can come out with PowerShell for Linux/Unix :-)
Then you would use WinRM
-Nikos
Νικοσ ΓιαννιοσWednesday, December 15, 2010 10:37 PM -
Hi Tamir,
I am using the open source provided at code project for SFTP. However it gives following error :
'Tamir.SharpSsh.jsch.Util' is inaccessible due to its protection level
Is Anyone aware of this error? How to resolve. Please helpMonday, January 3, 2011 7:59 AM -
Out of the solutions mentioned here, SharpSSH worked best for me. Download the binaries instead of trying to add the source project to your solution. When I did that, it did not work consistently for me. But the binaries work great. Here's how I use them:
public static void UploadToFTPSite(
string FilePath,
string Host,
string User,
string Password)
{
try
{
System.IO.FileInfo fileInf = new System.IO.FileInfo(FilePath);
SshConnectionInfo input = new SshConnectionInfo();
input.Host = Host;
input.User = User;
input.Pass = Password;
SshTransferProtocolBase sshCp = new Sftp(input.Host, input.User);
sshCp.Password = input.Pass;
sshCp.Connect();
string localFile = FilePath;
string remoteFile = fileInf.Name;
sshCp.Put(localFile, remoteFile);
sshCp.Close();
}
catch (Exception ex)
{
#if DEBUG
System.Diagnostics.Debugger.Break();
#endif
throw ex;
}
}Carlos A Merighe.
Friday, January 21, 2011 11:58 AM -
Guys! What you are looking for called SSH.NET now. It's further development of Sharp.SSH library and is completely reworked now. Check this out.
Thursday, June 9, 2011 9:31 PM -
it has passed a long time....
try http://www.example-code.com/csharp/sftp_readTextFile.asp and here is the document http://www.chilkatsoft.com/refdoc/csSFtpRef.html
这家伙很懒,什么都没写Tuesday, August 9, 2011 5:16 AM -
I tried the Chilkatsoft tool for a first connect and list directory files. Its quite intuitve to program and offers a good price compared with other commercial solutions.
However, error handling is done by boolean return value and three LastError Properties that allow to get last error in three different formats. So I have to handle the return value and the errorcode for each call. Why don't they use exceptions???
Friday, August 19, 2011 3:12 PM -
god knows...
这家伙很懒,什么都没写Monday, August 22, 2011 7:06 AM -
I have started creating a class library for SFTP transfers which uses the command line version of WinSCP for doing the hard work. I have created a DLL that stores the WinSCP executables as embedded resources and copy's them to the temp folder on instantiation.
I too, have used the Chilkat library before but decided to use WinSCP as it's free. I have started creating the library in the same way as Chilkat have done by storing the last error message of the last command run in a read only property. I have also used there method of setting a KeepSession log property to true for storing the full session log which is acquired from WinSCP.
I was just curious to know why you would rather use exceptions as opposed to a true or false value and a check last error property? Is changing my code to use exceptions a better way to go? For anyone interested, here is a link to an article discussing the basics on how to upload and download a file using VB.NET and WinSCP as a class library: http://zeusarticles.com/transfer-files-using-sftp-protocol-and-vbnet-free. The code in this article is similar to what I am using in the library I'm creating.
The class currently has methods for:
- UploadFile
- DownloadFile
- WriteFileText
- WriteFileBytes
- DeleteFile
- SetFileGroupAndOwner
- SetFilePermissions
- CreateDirectory
- DeleteDirectoy
Saturday, August 27, 2011 4:04 PM -
Ultimate SFTP component setup package has SFTP Console and SCP Console examples. It's a commercial product.Monday, May 7, 2012 1:50 PM
-
WinScp is the best sftp program for windows (also includes ftp/ftpes), is free, and has a .net library you can use (you don't have to use batch commands), so I'd strongly recommend using that over what is listed above.
- Proposed as answer by Carey Morgan Friday, October 26, 2012 6:43 PM
Saturday, August 11, 2012 5:55 PM -
if Winscp has a dotNet lib. that will be a perfect way.
这家伙很懒,什么都没写
Monday, August 13, 2012 7:36 AM -
So what do you suggest to accomplish this?Friday, September 7, 2012 12:02 AM
-
You can look at the following example
http://bsenyayla.blogspot.com/2012/09/ftp-upload-from-local-filesystem.html
Wednesday, September 12, 2012 12:12 PM