Internet and Web Applications Part 2 - FTP Program

Started by VelMurugan, Jul 16, 2008, 03:45 PM

Previous topic - Next topic

VelMurugan

In order to monitor the status of the connection, you can use the StateChanged event that is associated with Inet1 together with a set of the state constants that are listed in the following table.

Constant                              Value                          Description

icHostResolvingHost                 1                      The control is looking up the IP address of the specified host computer.

icHostResolved                        2                      The control successfully found the IP address of the specified host computer.

icConnecting                           3                      The control is connecting to the host computer.

icConnected                           4                       The control successfully connected to the host computer.

icRequesting                           5                       The control is sending a request to the host computer.

icRequestSent                        6                        The control successfully sent the request.

icReceivingResponse                7                        The control is receiving a response from the host computer.

icResponseReceived                 8                        The control successfully received a response from the host computer.

icDisconnecting                       9                        The control is disconnecting from the host computer.

icDisconnected                      10                        The control successfully disconnected from the host computer.

icError                                 11                         An error occurred in communicating with the host computer.

icResponseCompleted             12                         The request has been completed and all data has been received.


Under the StateChanged event, you use the Select Case...End Select statements to notify the users regarding the various states of the connection. The procedure is shown below:

Private Sub Inet1_StateChanged(ByVal State As Integer)

Select Case State
Case icError
MsgBox Inet1.ResponseInfo, , "File failed to transfer"

Case icResolvingHost
Label6.Caption = "Resolving Host"

Case icHostResolved
Label6.Caption = "Host Resolved"

Case icConnecting
Label6.Caption = "Connecting Host"

Case icConnected
Label6.Caption = "Host connected"

Case icReceivingResponse
Label6.Caption = "Receiving Response"

Case icResponseReceived
Label6.Caption = "Got Response"

Case icResponseCompleted
Dim data1 As String
Dim data2 As String
MsgBox "Download Completed"     
End Select
End Sub


 
The FTP program that I have created contains a form and a dialog box. The dialog box can be added by clicking on the Project item on the menu bar and then selecting the Add Form item on the drop-down list. You can either choose a normal dialog box or a login dialog box. The function of the dialog box is to accept the FTP address, the username and the password and then to connect to the server. After successful login, the dialog box will be hidden and the main form will be presented for the user to browse the remote directory and to choose certain files to download.

The interface of the login dialog is shown on the right.



The program for the login dialog is,

Option Explicit

Private Sub OKButton_Click()
Inet1.URL = Text1.Text
Inet1.UserName = Text2.Text
Inet1.Password = Text3.Text
Inet1.Execute , "DIR"
Form1.Show
Dialog.Hide
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
Select Case State
Case icError
MsgBox Inet1.ResponseInfo, , "File failed to transfer"
Case icResolvingHost
Label6.Caption = "Resolving Host"
Case icHostResolved
Label6.Caption = "Host Resolved"
Case icConnecting
Label6.Caption = "Connecting Host"
Case icConnected
Label6.Caption = "Host connected"
Case icReceivingResponse
Label6.Caption = "Receiving Response"
Case icResponseReceived
Label6.Caption = "Got Response"
Case icResponseCompleted
Dim data As String
Dim data1 As String
MsgBox "Transfer Completed"
Do       
            data1 = Inet1.GetChunk(1024, icString)
            data = data & data1
Loop While Len(data1) <> 0
Form1.Text6.Text = data
End Select
End Sub

Private Sub CancelButton_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub