Thanks for a nicely elaborated question.
Just to summarize:
The DoubleLogin proxy expects the following sequence of commands:
USER ProxyUser@FtpHost
PASS ProxyPassword
USER FtpUser
PASS FtpPassword
While your gateway seems to expect the following sequence of commands:
USER FtpUser@FtpHost
PASS FtpPassword
AUTH ProxyUser
RESP ProxyPassword
The another difference is that the DoubleLogin proxy uses common FTP authentication commands only (
USER
,
PASS
) while your proxy requires specific commands - the
AUTH
command is used for the SSL/TLS authentication and the
RESP
is not used in FTP protocol at all.
I'm afraid Rebex FTP/SSL really does not provide an instant proxy type suitable for your gateway, but the SendCommand
would be a reasonable solution here. If it succeeds, we would consider adding an support for this proxy type into our component, but for the 10 years of the Rebex FTP component we've never met a proxy gateway with this behavior.
I think your code is almost right, it needs only a one trick: do not use any pre-defined proxy and do the proxy authentication just using the Login
and SendCommand
method calls.
Additionally, I'd recommend to examine results of the FTP protocol responses:
var ftp = new Ftp();
ftp.Passive = false;
ftp.Settings.DoNotDetectFeatures = true;
//ftp.CommandSent += (sender, args) => { Console.WriteLine( ">> {0}", args.Command ); };
//ftp.ResponseRead += (sender, args) => { Console.WriteLine( "<< {0}", args.Response ); };
// Wouldn't be easier to use the instant component logging?
ftp.LogWriter = new FileLogWriter(@"c:\temp\log.txt", LogLevel.Debug);
ftp.Connect("gate.initech.com" ); // connect to the proxy gateway first
try {
// let the proxy to connect to the remote server
ftp.Login("remoteuser@initech-origin.cdnetworks.net", "remotepassword" );
ftp.SendCommand( "AUTH proxyuser" ); // proxy username
var response = ftp.ReadResponse();
// in common FTP authentication, the 3xx response means "password required"
// but you may have to modify the following condition,
// since your gateway may return another response even when password is required
if (response.Group == 3)
{
ftp.SendCommand( "RESP hunter2" ); // proxy password
ftp.ReadResponse();
}
// if the last command didn't succeed
if (response.Group != 2)
throw new FtpException(response);
} finally {
ftp.Disconnect();
}