Most of the options to fine-tune are already accessible through Ftp
object's Proxy
, Settings
and PortRange
properties. If you need to set any additional option, please let us know.
But if you absolutely need to achieve this right now yourself, you can use our socket factory functionality and implement a custom socket creation routine that provides a suitable socket to the Ftp
object.
If you use .NET 4.0 or higher and don't need to connect through a proxy, the following approach can be used:
public class FtpExt : Ftp
{
private class FtpSocketFactory : ISocketFactory
{
private readonly FtpExt _owner;
public FtpSocketFactory(FtpExt owner)
{
_owner = owner;
}
ISocket ISocketFactory.CreateSocket()
{
var socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
var handler = _owner.SocketCreated;
if (handler != null)
handler(_owner, new SocketCreatedEventArgs(socket));
return new ProxySocket(socket);
}
}
public EventHandler<SocketCreatedEventArgs> SocketCreated;
public FtpExt()
{
var factory = new FtpSocketFactory(this);
SetSocketFactory(factory);
}
}
The FtpExt
object inherits from Ftp
and adds a SocketCreated
event that gets called whether a new socket has been created. Then, you can customize it, like this:
var ftp = new FtpExt();
ftp.SocketCreated += (sender, e) =>
{
Socket socket = e.Socket;
socket.SendBufferSize = 256 * 1024;
socket.ReceiveBufferSize = 256 * 1024;
};
ftp.Connect("test.rebex.net");
ftp.Login("demo", "password");
ftp.GetList();