Inet Error trapping

N

nutraf

Hi,
i'm usign the following code to download via Inet froma a FTP server.

On Error GoTo GestErr
lblstatus.Caption = ""

downloadfile = True
With Inet1
..Protocol = icFTP
..URL = "ftp://server"
..UserName = "username"
..Password = "password"

..Execute .URL, "SIZE invio/prova.txt"

Do While Inet1.StillExecuting
DoEvents
Loop
dimensione = Inet1.GetChunk(1024)
ProgressBar1.Value = 0
ProgressBar1.Max = dimensione

..Execute .URL, "GET invio/prova.txt C:\prova.txt"

Do While Inet1.StillExecuting
DoEvents

ProgressBar1.Value = FileLen("C:\prova.txt")
perc = RoundN((ProgressBar1.Value / dimensione) * 100, 0)
Testo1 = perc & "%"
Loop



z = (.ResponseCode = 0)
..Execute .URL, "CLOSE"
..Execute .URL, "QUIT"
End With
Do While Inet1.StillExecuting
DoEvents
Loop
Inet1.Cancel
GestErrEsci:

Exit Sub

GestErr:

Select Case Err
Case icNameNotResolved, icCannotConnect,
icConnectFailed, icInternetDisconnected
MsgBox "Problema durante la connessione...",
vbCritical + vbOKOnly
Case icInetTimeout, icTimeout
MsgBox "Timeout....", vbExclamation
Case icUrlOpenFailed, icInvalidURL, icRequestFailed
MsgBox "Indirizzo non valido...", vbCritical +
vbOKOnly
Case Else
MsgBox "FTP Errore " & Err & " : " & Error$ & "",
vbCritical + vbOKOnly, "Attenzione"

End Select
Resume GestErrEsci




Private Sub Inet1_StateChanged(ByVal State As Integer)
Select Case State
Case icResolvingHost
lblstatus.Caption = lblstatus.Caption & "Risolvo indirizzo
IP Host" & vbCr & vbLf
Case icHostResolved
lblstatus.Caption = lblstatus.Caption & "indizzo IP Host
risolto" & vbCr & vbLf
Case icConnecting
lblstatus.Caption = lblstatus.Caption & "Connessione ..."
& vbCr & vbLf
Case icConnected
lblstatus.Caption = lblstatus.Caption & "Connesso" & vbCr
& vbLf
Case icRequesting
lblstatus.Caption = lblstatus.Caption & "Richiesta in
Corso ..." & vbCr & vbLf
Case icRequestSent
lblstatus.Caption = lblstatus.Caption & "Richiesta
Inviata" & vbCr & vbLf
Case icReceivingResponse
lblstatus.Caption = lblstatus.Caption & "Ricezione
risposta..." & vbCr & vbLf
Case icResponseReceived
lblstatus.Caption = lblstatus.Caption & "Risposta
Ricevuta" & vbCr & vbLf
Case icDisconnecting
lblstatus.Caption = lblstatus.Caption &
"Disconnessione ..." & vbCr & vbLf
Case icDisconnected
lblstatus.Caption = lblstatus.Caption & "Disconnesso" &
vbCr & vbLf
Case icError
lblstatus.Caption = lblstatus.Caption & "Errore " &
Inet1.ResponseCode & ":" & Inet1.ResponseInfo & vbCr & vbLf
Case icResponseCompleted
lblstatus.Caption = lblstatus.Caption & "Operazione
Completata - Dati ricevuti" & vbCr & vbLf
End Select
Debug.Print Inet1.ResponseCode & ":" & Inet1.ResponseInfo
End Sub

I dont know if error trapping is correct....because if i try to login
with an incorrect password VBA error trapping stars before Inet state
become 11 IcError

How can I disconnect Inet control if i get error?
If I use Inet1.cancel i get VBA error Property not valid.

Thanks
Bye
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top