Example topics
/ Receiving a file to memory (VB example)
In This Topic
Receiving a file to memory (VB example)
In This Topic
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.
' 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
' 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