This example demonstrates the 8 following steps for receiving a file's data directly to memory:
-
Specify the FTP server's address
-
Specify the username to login
-
Specify the password for the username
-
Connect to the FTP server
-
Start receiving a file to memory
-
Process the data being received
-
Disconnect from the FTP server
-
Perform error handling
The following code assumes you have placed an XceedFtp control and a text box on a form, named 'XceedFtp1' and 'Text1' respectively.
The first section of code below demonstrates all steps except step (6). Step (6), the handler for the ReceivingMemoryFileData event, is found right after.
Visual Basic |
Copy Code |
Call XceedFtp1.License( "your license key" )
XceedFtp1.ServerAddress = "192.168.0.200" ' step (1) XceedFtp1.UserName = "anonymous" ' step (2) XceedFtp1.Password = "guest" ' step (3)
On Error Resume Next ' step (8)
Call XceedFtp1.Connect ' step (4)
If Err.Number = 0 Then ' step (8) MsgBox "Successfully connected to FTP server. Starting the receive operation."
Call XceedFtp1.ReceiveMemoryFile("readme.txt", 0, fmoSingleBlock) ' step (5)
' In the line above, we chose to receive the data in a single ' block of data. So the ReceivingMemoryFile event will only ' be triggered once. You can change the value of the third ' parameter to receive the data in many smaller chunks, ' whenever data is received by the Xceed FTP Library.
If Err.Number = 0 Then ' step (8) MsgBox "Successfully received the file to memory" Else MsgBox "Receive error. Description: " & Err.Description & ". Error#" & Err.Number End If
Call XceedFtp1.Disconnect ' step (7) Else MsgBox "Connect error. Description: " & Err.Description & ". Error#" & Err.Number ' step (8) End If
' Step (6): The following code, which simply displays the received ' file data in the textbox on the form, must go into the error ' handler for the ReceivingMemoryFileData event. Note: Do not ' copy and paste the event declaration from the code below. Have the header ' automatically generated by VB. You can copy the code between the ' header and the 'End Sub' though.
Private Sub XceedFtp1_ReceivingMemoryFileData(ByVal sRemoteFilename As String, ByVal lFileSize As Long, vaData As Variant, ByVal bEndOfData As Boolean) Text1.Text = StrConv(vaData, vbUnicode) End Sub
|