0 votes
by (650 points)
edited

Hi, What is the easiest way to implement a FTP over SSH. Which component (FTP or SFTP, SSH) should I use. Does an exemple exist ? Thanks

Log from the first solution:

Hi, What is the easiest way to implement a FTP over SSH. Which component (FTP or SFTP, SSH) should I use. Does an exemple exist ? Thanks

Log from the first solution:

16:11:31.741 Info Info: Connecting to ftp.devolutions.net:21 using Ftp 4.0.4444.0.   
16:11:31.759 Info Info: Using proxy Rebex.Net.SshSession+23CaaWZ.
16:11:32.125 Info Response: 220 Microsoft FTP Service
16:11:32.139 Info Command: USER DevolutionsADM
16:11:32.420 Info Response: 331 Password required for DevolutionsADM.
16:11:32.424 Info Command: PASS ***
16:11:33.809 Info Response: 230-FTP-SSL (AUTH TLS, Explicit FTPS or FTPES) security is available
16:11:33.812 Info Response: 230 User logged in.
16:11:33.815 Info Command: FEAT
16:11:34.168 Info Response: 211-Extended features supported:
16:11:34.170 Info Response: LANG EN*
16:11:34.179 Info Response: UTF8
16:11:34.183 Info Response: AUTH TLS;TLS-C;SSL;TLS-P;
16:11:34.192 Info Response: PBSZ
16:11:34.196 Info Response: PROT C;P;
16:11:34.201 Info Response: CCC
16:11:34.208 Info Response: HOST
16:11:34.212 Info Response: SIZE
16:11:34.216 Info Response: MDTM
16:11:34.220 Info Response: 211 END
16:11:34.226 Info Command: OPTS UTF8 ON
16:11:34.542 Info Response: 200 OPTS UTF8 command successful - UTF8 encoding now ON.
16:11:35.354 Info Command: CWD /
16:11:35.572 Info Response: 250 CWD command successful.
16:11:35.595 Info Command: TYPE A
16:11:35.745 Info Response: 200 Type set to A.
16:11:35.768 Error Info: System.NotSupportedException: The method or operation is not implemented.
    at gbMKS.1ePSrkZ.BeginListen(ISocket controlSocket, AsyncCallback callback, Object state)
    at gbMKS.OTxlj.rOZTZ(ISocket )
    at Rebex.Net.Ftp.2aYAeNZ(String , Boolean , OTxlj , Int64 , String , String , Int64 , FtpTransferState )
    at Rebex.Net.Ftp.zo0DuZ(String , Boolean , Stream , Int64 , String , 27NpLhZ ) 16:11:35.782 Error Info: System.NotSupportedException: The method or operation is not implemented.
    at gbMKS.1ePSrkZ.BeginListen(ISocket controlSocket, AsyncCallback callback, Object state)
    at gbMKS.OTxlj.rOZTZ(ISocket )
    at Rebex.Net.Ftp.2aYAeNZ(String , Boolean , OTxlj , Int64 , String , String , Int64 , FtpTransferState )
    at Rebex.Net.Ftp.zo0DuZ(String , Boolean , Stream , Int64 , String , 27NpLhZ )
by (650 points)
edited

I tried this solution. It connects but I have an issue. It doesn't seems to be able to do all ftp operations.

Do I do something wrong ?

Log: I put the log in the original question.

Thanks

by (144k points)
edited

It looks like you are trying to use active transfer mode (=you added ftp.Passive = false to the code below). FTP over SSH currently only supports passive mode (ftp.Passive = true).

by (144k points)
edited

More information: Active mode (over SSH) is unsupported mostly due to a fact that a) most SSH servers are configured to disallow 'incoming' tunnels (except those from their loopback address) and b) for those that do support 'incoming' tunnels, there is no straightforward and reliable way to determine the appropriate 'listen' IP address (which means it would have to be supplied by the client).

2 Answers

+1 vote
by (144k points)
edited
 
Best answer

All you need to implement FTP over SSH is available in Rebex FTP/SSL (since version 2012 R1).

Sample C# code:

        // establish an SSH session to the server you wish to connect through
        SshSession ssh = new SshSession();
        ssh.Connect("ssh.example.org");
        ssh.Authenticate("username", "password");

        // create an instance of Ftp
        Ftp ftp = new Ftp();

        // instruct it to route connections through the SSH session
        ftp.SetSocketFactory(ssh.ToSocketFactory());

        // connect to the FTP server, authenticate and download a file
        ftp.Connect("ftp.rebex.net");
        ftp.Login("anonymous", "guest");
        ftp.GetFile("readme.txt", "readme.txt");
by (650 points)
edited

I tried this solution. It connects but I have an issue. It doesn't seems to be able to do all ftp operations.

Do I do something wrong ?

Log: I put the log in the original question.

Thanks

by (144k points)
edited

I just responded above.

by (650 points)
edited

Thanks!!! Works great!

0 votes
by (140 points)
edited

This worked great for me. This is setting up an encrypted control channel but is the data channel also being encrypted?

by (144k points)
edited

Yes, it is! Both control channel and data channels are established using the Ftp object's socket factory, which in this case is provided by the same SSH session, which means both are encrypted using SSH. In fact, both FTP control commands and data are acutally transmitted between the client and the SSH server using a signle TCP connection. This is possible due to SSH protocol's capability to encapsulate multiple independent channels. Check out http://www.rebex.net/sftp.net/features/ssh.aspx to see other useful features of the SSH core (which is a part of Rebex FTP/SSL as well).

...