A new FTP2 event is being added to allow programs to be notified of the port number used for active data connections for uploading and downloading files. (Active data connections are such that the client creates a data socket, binds to a random port above 1024, notifies the FTP server and listens for a connection request from the FTP server. Passive data connections are the opposite — the FTP server creates the data socket, notifies the client of the port number, and listens for the connection request.)
The "DataPort" event is fired prior to the client notifying the server of the port number (via the PORT command).
The DataPort event is not yet publicly available, but will be included in the next FTP2 version release.
A C# sample is listed here:
<font size=2 face=courier>
public void OnDataPort(object source, Chilkat.DataPortEventArgs args)
{
MessageBox.Show(Convert.ToString(args.Port));
}
private void button1_Click(object sender, EventArgs e)
{
Chilkat.Ftp2 ftp2 = new Chilkat.Ftp2();
ftp2.UnlockComponent("test");
ftp2.Hostname = "ftp.chilkatsoft.com";
ftp2.Username = "myLogin";
ftp2.Password = "myPassword";
ftp2.EnableEvents = true;
ftp2.OnDataPort += new Chilkat.Ftp2.DataPortEventHandler(OnDataPort);
bool b = ftp2.Connect();
if (!b)
{
MessageBox.Show(ftp2.LastErrorText);
}
ftp2.ChangeRemoteDir("images");
ftp2.GetFile("dude.gif", "dude.gif");
ftp2.Disconnect();
MessageBox.Show("Done!");
}
</font>