Capturing FTP related events

Top  Previous  Next

The Ftp class may publish one or more events during the lifetime of an FTP session. Any object that subscribes to events published by the Ftp class can receive and process these events.

 

The FtpConnectEvent is fired upon successful connection to the FTP server.

The FtpDisconnectedEvent is fired when a connection to the FTP server is released.

The FtpConnectionLostEvent is fired when a connection to the FTP server is unexpectedly closed.

The FtpCommandEvent is fired when a command is sent to the FTP server.

The FtpResponseEvent is fired when a response is sent from the FTP server.

The FtpDownloadEvent is fired when data is received from the FTP server.

The FtpUploadEvent is fired when data is sent to the FTP server.

The FtpListingEvent is fired when a directory listing method is invoked.

The FtpProgressEvent is fired during the data transfer process.

 

 

 

Capturing the FtpConnectEvent Event

 

To capture and respond to the FtpConnectEvent do the following:

 

1.Create a method that has the same signature as the FtpConnectEventHandler delegate.
2.Add code within the newly created method to handle the event.
3.Subscribe newly created method to capture the FtpConnectEvent when fired.

 

Example

 

[C#]

myFtp.FtpConnectedEvent += new FtpConnectEventHandler(OnConnected);

 

private void OnConnected(object sender, FtpConnectEventArgs e) {

 // handle connect event

}

 

 

[Visual Basic]

Public WithEvents myFtp As Jscape.Ftp.Ftp

 

Public Sub OnConnected(ByVal sender As Object, ByVal e As FtpConnectEventArgs) Handles myFtp.FtpConnectedEvent

 ' handle connect event

End Sub

 

 

Capturing the FtpDisconnectedEvent Event

 

To capture and respond to the FtpDisconnectedEvent do the following:

 

1.Create a method that has the same signature as the FtpConnectEventHandler delegate.
2.Add code within the newly created method to handle the event.
3.Subscribe newly created method to capture the FtpDisconnectedEvent when fired.

 

Example

 

[C#]

myFtp.FtpDisconnectedEvent += new FtpConnectEventHandler(OnDisconnected);

 

private void OnDisconnected(object sender, FtpConnectEventArgs e) {

 // handle disconnect event

}

 

 

[Visual Basic]

Public WithEvents myFtp As Jscape.Ftp.Ftp

 

Public Sub OnDisconnected(ByVal sender As Object, ByVal e As FtpConnectEventArgs) Handles myFtp.FtpDisconnectedEvent

 ' handle disconnect event

End Sub

 

 

Capturing the FtpConnectionLostEvent Event

 

To capture and respond to the FtpConnectionLostEvent do the following:

 

1.Create a method that has the same signature as the FtpConnectEventHandler delegate.
2.Add code within the newly created method to handle the event.
3.Subscribe newly created method to capture the FtpConnectionLostEvent when fired.

 

Example

 

[C#]

myFtp.FtpConnectionLostEvent += new FtpConnectEventHandler(OnConnectionLost);

 

private void OnConnectionLost(object sender, FtpConnectEventArgs e) {

 // handle lost connection event

}

 

 

[Visual Basic]

Public WithEvents myFtp As Jscape.Ftp.Ftp

 

Public Sub OnConnectionLost(ByVal sender As Object, ByVal e As FtpConnectEventEventArgs) Handles myFtp.FtpConnectionLostEvent

 ' handle lost connection event

End Sub

 

 

Capturing the FtpCommandEvent Event

 

To capture and respond to the FtpCommandEvent do the following:

 

1.Create a method that has the same signature as the FtpCommandEventHandler delegate.
2.Add code within the newly created method to handle the event.
3.Subscribe newly created method to capture the FtpCommandEvent when fired.

 

Example

 

[C#]

myFtp.FtpCommandEvent += new FtpCommandEventHandler(OnCommand);

 

private void OnCommand(object sender, FtpCommandEventArgs e) {

 // handle command sent event

}

 

 

[Visual Basic]

Public WithEvents myFtp As Jscape.Ftp.Ftp

 

Public Sub OnCommand(ByVal sender As Object, ByVal e As FtpCommandEventArgs) Handles myFtp.FtpCommandEvent

 ' handle command sent event

End Sub

 

 

Capturing the FtpResponseEvent Event

 

To capture and respond to the FtpResponseEvent do the following:

 

1.Create a method that has the same signature as the FtpResponseEventHandler delegate.
2.Add code within the newly created method to handle the event.
3.Subscribe newly created method to capture the FtpResponseEvent when fired.

 

Example

 

[C#]

myFtp.FtpResponseEvent += new FtpCommandEventHandler(OnResponse);

 

private void OnResponse(object sender, FtpCommandEventArgs e) {

 // handle server response event

}

 

 

[Visual Basic]

Public WithEvents myFtp As Jscape.Ftp.Ftp

 

Public Sub OnResponse(ByVal sender As Object, ByVal e As FtpCommandEventArgs) Handles myFtp.FtpResponseEvent

 ' handle server response event

End Sub

 

 

Capturing the FtpDownloadEvent Event

 

To capture and respond to the FtpDownloadEvent do the following:

 

1.Create a method that has the same signature as the FtpDownloadEventHandler delegate.
2.Add code within the newly created method to handle the event.
3.Subscribe newly created method to capture the FtpDownloadEvent when fired.

 

Example

 

[C#]

myFtp.FtpDownloadEvent += new FtpDownloadEventHandler(OnDownload);

 

private void OnDownload(object sender, FtpDownloadEventArgs e) {

 // handle download event

}

 

 

[Visual Basic]

Public WithEvents myFtp As Jscape.Ftp.Ftp

 

Public Sub OnDownload(ByVal sender As Object, ByVal e As FtpDownloadEventArgs) Handles myFtp.FtpDownloadEvent

 ' handle download event

End Sub

 

 

Capturing the FtpUploadEvent Event

 

To capture and respond to the FtpUploadEvent do the following:

 

1.Create a method that has the same signature as the FtpDownloadEventHandler delegate.
2.Add code within the newly created method to handle the event.
3.Subscribe newly created method to capture the FtpUploadEvent when fired.

 

Example

 

[C#]

myFtp.FtpUploadEvent += new FtpDownloadEventHandler(OnUpload);

 

private void OnUpload(object sender, FtpDownloadEventArgs e) {

 // handle upload event

}

 

 

[Visual Basic]

Public WithEvents myFtp As Jscape.Ftp.Ftp

 

Public Sub OnUpload(ByVal sender As Object, ByVal e As FtpDownloadEventArgs) Handles myFtp.FtpUploadEvent

 ' handle upload event

End Sub

 

 

Capturing the FtpListingEvent Event

 

To capture and respond to the FtpListingEvent do the following:

 

1.Create a method that has the same signature as the FtpListingEventHandler delegate.
2.Add code within the newly created method to handle the event.
3.Subscribe newly created method to capture the FtpListingEvent when fired.

 

Example

 

[C#]

myFtp.FtpListingEvent += new FtpListingEventHandler(OnListing);

 

private void OnListing(object sender, FtpListingEventArgs e) {

 // handle listing event

}

 

 

[Visual Basic]

Public WithEvents myFtp As Jscape.Ftp.Ftp

 

Public Sub OnListing(ByVal sender As Object, ByVal e As FtpListingEventArgs) Handles myFtp.FtpListingEvent

 ' handle listing event

End Sub

 

 

Capturing the FtpProgressEvent Event

 

To capture and respond to the FtpProgressEvent do the following:

 

1.Create a method that has the same signature as the FtpProgressEventHandler delegate.
2.Add code within the newly created method to handle the event.
3.Subscribe newly created method to capture the FtpProgressEvent when fired.

 

Example

 

[C#]

myFtp.FtpProgressEvent += new FtpProgressEventHandler(OnProgress);

 

private void OnProgress(object sender, FtpProgressEventArgs e) {

 // handle progress event

}

 

 

[Visual Basic]

Public WithEvents myFtp As Jscape.Ftp.Ftp

 

Public Sub OnProgress(ByVal sender As Object, ByVal e As FtpProgressEventArgs) Handles myFtp.FtpProgressEvent

 ' handle progress event

End Sub