Ftps thrugh a proxy

0 votes
asked May 21, 2013 by tjomi (120 points)
edited May 31, 2013

Hello I have been trying to connect to a ftp site that uses TSL/SSL security. After trying to use the native libraries in .net i discovered that they did not support ftps through a proxy, and after searching online i came upon the Rebex libraries which several people on different sites claimed could connect too a ftps site through a proxy. I have been trying for a week now with little success and i am hoping that someone on this board could help me.

The code i am using is this

            TlsParameters tls = new TlsParameters();
            tls.CertificateVerifier = CertificateVerifier.AcceptAll;
            Ftp client = new Ftp();
            client.LogWriter = new Rebex.FileLogWriter(@"C:\temp\rebex.log");
            client.LogWriter.Level = Rebex.LogLevel.Verbose;
            client.Proxy = new FtpProxy(FtpProxyType.HttpConnect,ProxyAdress,ProxyPort);

            client.Connect(FTPS_adress, FTPS_port, tls, FtpSecurity.Explicit);

            client.Secure(tls);
            client.Login(usernam, password);

            FtpResponse resp = client.ReadResponse();

            "Do something"

            client.Disconnect();

Regarding the bad code structure, right now i am desperately trying to get a successful a connection so i don't care about it.

When i try to connect with the proxytype HttpConnect i get the response: error Invalid HTTP response.

and this log entry:

2013-05-21 10:01:01.953 Opening log file.
2013-05-21 10:01:02.009 INFO Ftp(1)[10] Info: Connecting to XXXXXXX:XXX using Ftp 4.0.4700.0 (trial version).
2013-05-21 10:01:02.010 INFO Ftp(1)[10] Info: Using proxy HTTP CONNECT PROXYXXX:XXX.
2013-05-21 10:01:02.150 ERROR Ftp(1)[10] Info: Rebex.Net.FtpException: Invalid HTTP response. ---> Rebex.Net.ProxySocketException: Invalid HTTP response.
   at gbMKS.1vL03D.1fZglFZ(String )
   at gbMKS.ULE4T.1fZglFZ(IAsyncResult , String , Int32 )
   at gbMKS.ULE4T.1QP6MBZ(IAsyncResult , Int32 )
   at Rebex.Net.ProxySocket.EndConnect(IAsyncResult asyncResult)
   at gbMKS.l7gsR..ctor(Ftp ftp, ISocketFactory factory, String serverName, Int32 serverPort)
   at Rebex.Net.Ftp.2eOMSNZ(String , Int32 , TlsParameters , FtpSecurity )
   --- End of inner exception stack trace ---
   at Rebex.Net.Ftp.2eOMSNZ(String , Int32 , TlsParameters , FtpSecurity )

And if i try it with the proxytype ftpOpen i get the response: error TLS/SSL through FTP proxy is not possible.

and this entry in the log:

2013-05-21 10:04:10.463 Opening log file.
2013-05-21 10:04:10.563 ERROR Ftp(1)[10] Info: System.InvalidOperationException: TLS/SSL through FTP proxy is not possible.
   at Rebex.Net.Ftp.2eOMSNZ(String , Int32 , TlsParameters , FtpSecurity )

I also tried something i learned when reading up on the .net ftp libraries, apparently they need the ftp:// prefix infront of the adresses, i tried this also but got the same response.

I am also able to establish a connection with the ftp site with CuteFtp, so i do not know why i cannot get a connection myself. Is there anyone who have successfully managed to connect to an ftp site through a proxy using TSL/SSL? Or does anyone else see a glaring error in my code that i do not see?

Applies to: Rebex FTP/SSL

1 Answer

0 votes
answered May 21, 2013 by Jan Sotola (16,540 points)
edited May 31, 2013

We've never encountered a requirement for an FTP connection over TLS/SSL through proxy. I think most of the FTP proxies even doesn't support it.

You are writing you've successfully connected using the CuteFtp. Could you, please send us the communication log from that successful connection? The CuteFtp shows the log near the bottom edge of the current connection tab. You can either post the log here into the forum or send it to support@rebex.net.

Anyway, if the proxy really supported FTP/SSL connections, you could connect through the proxy without using the client.Proxy property similarly as described in this article.

commented May 31, 2013 by tjomi (120 points)
edited May 31, 2013

Hello Thank you for your answer, it helped me getting the solution working. It worked when i used double login.

but since our proxy(TLSWrapper) doesn't use login i only had to login to the ftps server i wanted. I don't know if it would have created problems if our proxy required a login, but as long as it doesn't i'm happy 8)

commented May 31, 2013 by Jan Sotola (16,540 points)
edited May 31, 2013

I'm afraid I don't understand your situation well. Could you, please, write me a sequence of Ftp methods you are calling now to connect through the proxy?

...