Execute Method Example

The example shows a series of common FTP operations using the Execute method. The example assumes that three TextBox controls exist on the form. The first, txtURL contains the URL of the FTP server. The second, txtRemotePath, contains additional information needed by the particular command. The third, txtResponse, contains the response of the server.

Private Sub cmdChangeDirectory_Click()
   ' Change directory to txtRemotePath.
   Inet1.Execute txtURL.Text, "CD " & _
   txtRemotePath.Text
End Sub

Private Sub cmdDELETE_Click()
   ' Delete the directory in txtRemotePath.
   Inet1.Execute txtURL.Text, "DELETE " & _
   txtRemotePath.Text
End Sub

Private Sub cmdDIR_Click()
   Inet1.Execute txtURL.Text, "DIR FindThis.txt"
End Sub

Private Sub cmdGET_Click()
   Inet1.Execute txtURL.Text, _
   "GET GetThis.txt C:\MyDocuments\GotThis.txt"
End Sub

Private Sub cmdSEND_Click()
   Inet1.Execute txtURL.Text, _
   "SEND C:\MyDocuments\Send.txt SentDocs\Sent.txt"
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
   ' Retrieve server response using the GetChunk 
   ' method when State = 12.

   Dim vtData As Variant ' Data variable.
   Select Case State
   ' ... Other cases not shown.
   Case icError ' 11
      ' In case of error, return ResponseCode and 
      ' ResponseInfo.
      vtData = Inet1.ResponseCode & ":" & _
      Inet1.ResponseInfo
   Case icResponseCompleted ' 12
      Dim vtData As Variant
      Dim strData As String 
      Dim bDone As Boolean: bDone = False

      ' Get first chunk.
      vtData = Inet1.GetChunk(1024, icString)
      DoEvents

      Do While Not bDone
         strData = strData & vtData
         ' Get next chunk.
         vtData = Inet1.GetChunk(1024, icString)
         DoEvents

         If Len(vtData) = 0 Then
            bDone = True
         End If
      Loop
      txtData.Text = strData
   End Select
   
End Sub