Results 1 to 4 of 4

Thread: Downloading Using Inet Control

  1. #1

    Thread Starter
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261
    I saw once A sample on VB-world how to ftp a file using Inet .. I got it .. but it is not working for some reason ..
    I mean it is not downloading anything ...
    - regards -
    - razzaj -

  2. #2

    Smile

    Show me the code that you have written. I had that problem in my application. i have solved it.
    Madhusudana Gorthi [email protected]
    Senior Software Engineer
    www.stgil.com

  3. #3

    Thread Starter
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261
    Code:
    Private Const MAX_PATH = 260
    Dim aCmd As String, aPath As String, lBytes As Long, lBuf As Long, aFile As String
    
    
    
    Private Sub mnu_View_Click()
     Me.Hide
     Load Form2
     
    End Sub
    
    Private Sub nmu_Initialise_Click()
    
     Timer1.Interval = vTimer
     Timer1.Enabled = True
     
    End Sub
    
    Private Sub Timer1_Timer()
     Dim adata As String
     
     Timer1.Enabled = False
     
     
       With Inet1
            .Cancel
            .Protocol = icFTP
            .URL = vServer1
            .UserName = vUser1
            .Password = vPassword1
       End With
         
         
        
       MousePointer = vbHourglass
       aCmd = "CD " & vPath1
       
       Inet1.Execute , aCmd
           
       Status.Panels(2).Text = vServer1
       Status.Panels(3).Text = "Connecting To Server..."
       
       While Inet1.StillExecuting
             DoEvents
       Wend
       
       Status.Panels(1).Text = " Connected"
       
        
       aCmd = "DIR"
       
       
       Status.Panels(2).Text = vServer1
       Status.Panels(3).Text = "Refreshing"
    
       Inet1.Execute , aCmd
       
       While Inet1.StillExecuting
             DoEvents
       Wend
     
       
       Status.Panels(3).Text = "Done"
       
       
       For x = 0 To List1.ListCount - 1
        
        FName = List1.List(x)
        
            aCmd = "SIZE"
            Status.Panels(3).Text = "Getting Info : " & FName
            Inet1.Execute , aCmd & " " & FName
            Do While Inet1.StillExecuting: DoEvents: Loop
            aCmd = "GET"
            MousePointer = vbHourglass
            lBuf = FreeFile
            aFile = Space$(MAX_PATH)
            k = GetShortPathName(aPath & FName, aFile, MAX_PATH)
            aFile = Left$(aFile, k)
           
           ' If Len(Dir$(aFile)) Then
          '     Kill aFile
         '   End If
            
            Inet1.Execute , aCmd & " " & FName & " " & aFile
           
            Status.Panels(3).Text = "Downloading : " & FName
    
            
            Do While Inet1.StillExecuting: DoEvents: Loop
                
            GetData adata
            
            Open FName For Random As #1
                 Put #1, , adata
            Close #1
      
       Next x
      
      
            Status.Panels(3).Text = "Done "
         
      
    End Sub
    Private Sub Inet1_StateChanged(ByVal State As Integer)
        Dim adata As String, a As String, k As Long, aStat As String
        Select Case State
            Case icNone
                aStat = ""
            Case icResolvingHost
                aStat = "Resolving Host"
            Case icHostResolved
                aStat = "Host Resolved"
            Case icConnecting
                aStat = "Connecting"
            Case icConnected
                aStat = "Connected"
            Case icRequesting
                aStat = "Sending Request"
            Case icRequestSent
                aStat = "Request Sent"
            Case icReceivingResponse
                aStat = "Receiving Response"
            Case icResponseReceived
                aStat = "Response Received"
            Case icDisconnecting
                aStat = "Disconnecting"
            Case icDisconnected
                aStat = "Disconnected"
            Case icError
                aStat = "Remote Error"
                MousePointer = vbDefault
            Case icResponseCompleted
                 DoEvents
                Select Case aCmd
                    Case "DIR"
                       
                        List1.Clear
                        GetData adata
                       ' List1.AddItem ".."
                        Do While Len(adata)
                            k = InStr(adata, vbCrLf)
                            If k Then
                                a = Left$(adata, k - 1)
                                adata = Mid$(adata, k + 2)
                            Else
                                a = adata
                                adata = ""
                            End If
                            If Len(Trim$(a)) Then List1.AddItem Trim$(a)
                        Loop
                    Case "SIZE"
                        Status.Panels(1).Text = "Bytes To Go:"
                        GetData adata
                        Status.Panels(1).Text = Trim$(adata)
                        lBytes = Val(adata)
                    Case "GET"
                        Status.Panels(3).Text = "File Retrieved: " & vbCrLf & aFile
                    Case "PUT"
                        Status.Panels(3).Text = "File Sent: " & vbCrLf & aFile
                End Select
                MousePointer = vbDefault
                Exit Sub
        End Select
        Status.Panels(1).Text = aStat
    End Sub
    
    Public Function IExecute(Command As String) As Boolean
    
      
     Inet1.Execute , Command
       
     While Inet1.StillExecuting
           DoEvents
     Wend
     
     IExecute = True
     
    End Function
    Private Sub GetData(adata As String)
        Dim vData As Variant
        Do
            vData = Inet1.GetChunk(512, icString)
            DoEvents
            If Len(vData) = 0 Then Exit Do
            adata = adata & vData
            Label1.Caption = CStr(Len(adata))
        Loop
    End Sub
    - regards -
    - razzaj -

  4. #4
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    Here you are...the following code will upload and download specified.
    Code:
    With Inet1
        .Cancel
        .Protocol = icFTP
        .url = "123.123.123.123"
        .UserName = "me"
        .Password = "xxxx"
    End With
    'upload a file
    Inet1.Execute , "PUT C:\test.txt test.txt"
    'download file and download it to C:\test.txt
    Inet1.Execute , "Get test.txt C:\test.txt"

    Gl,
    D!m
    Dim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width