2 Replies - 896 Views - Last Post: 16 September 2012 - 12:19 AM Rate Topic: -----

#1 maheshsanka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-September 12

Problem with FTP

Posted 13 September 2012 - 04:34 AM

Hi ,

I am new to FTP.

by vb6 i need to connect with ftp. and display all the folders in tree list view.
The code which i had is displaying some folders only . It is not displaying all other folders.

Private Sub cmdConnect_Click()
LstFtpFiles.clear
trvFtpFldrs.Nodes.clear
trvFtpFldrs.Nodes.Add , , "ROOT", "Root", "ClosFldr"
trvFtpFldrs.Nodes("ROOT").Selected = True
If TxtFtp.Text <> Trim("") Or TxtUsrNm.Text <> Trim("") Or TxtPW.Text <> Trim("") Then
   With Inet1
                 .URL = TxtFtp.Text
                 .Username = TxtUsrNm.Text
                 .Password = TxtPW.Text
                 status = ("DIR") 'Triggers the DisplayData Routine
                 .Execute , "DIR"
                 UsrFriendly = ("OK!")
   End With
Else
    If TxtFtp.Text = "" Then
       MsgBox "Please Enter FTP ", vbInformation
       Exit Sub
    ElseIf TxtUsrNm.Text = "" Then
       MsgBox "Please Enter User Name ", vbInformation
       Exit Sub
    Else
      MsgBox "Please Enter Password", vbInformation
      Exit Sub
    End If
End If
End Sub
Private Sub Inet1_StateChanged(ByVal State As Integer)
   LblStatus.Caption = ("Working on Last Request")
    
    Select Case State
        Case Is = 1
        LblStatus.Caption = "The control is looking up the IP address of the specified host computer. (icHostResolvingHost)"
    Case Is = 2
        LblStatus.Caption = "The control successfully found the IP address of the specified host computer. (icHostResolved)"
    Case Is = 3
        LblStatus.Caption = "The control is connecting to the host computer. (icConnecting)"
    Case Is = 4
        LblStatus.Caption = "The control successfully connected to the host computer. (icConnected)"
    Case Is = 5
        LblStatus.Caption = "The control is sending a request to the host computer. (icRequesting)"
    Case Is = 6
        LblStatus.Caption = "The control successfully sent the request. (icRequestSent)"
    Case Is = 7
        LblStatus.Caption = "The control is receiving a response from the host computer. (icReceivingResponse)"
    Case Is = 8
        LblStatus.Caption = "The control successfully received a response from the host computer. (icResponseReceived)"
    Case Is = 9
        LblStatus.Caption = "The control is disconnecting from the host computer. (icDisconnecting)"
    Case Is = 10
        LblStatus.Caption = "The control successfully disconnected from the host computer. (icDisconnected)"
    Case Is = 11
        LblStatus.Caption = "An error occurred in communicating with the host computer. (icError)"
    Case Is = 12  'request completed, now get the data
    LblStatus.Caption = "Status : You Are Con&nected. (icResponseCompleted) - " & UsrFriendly
         StrData = ""
        Dim Bdone As Boolean
        Bdone = False
        ' Get first chunk.
        vtData = Inet1.GetChunk(1024, icString)
        Do While Not Bdone
           StrData = StrData & vtData
           MsgBox StrData
           DoEvents
           ' Get next chunk.
           vtData = Inet1.GetChunk(1024, icString)
           If Len(vtData) = 0 Then
              Bdone = True 'If done (vtData transfer's done) ,then it's not gonna loop anymore.
              LblStatus.ForeColor = vbBlack
           End If
        Loop
        Timer4.Interval = 1000
        Timer4.Enabled = True
    End Select
End Sub
Private Sub trvFtpFldrs_Collapse(ByVal Node As MSComctlLib.Node)
    Node.Image = "ClosFldr"
End Sub
Private Sub DisplayData()
On Error GoTo MyErr
'display the data .
'Use the split function to parse the data for us
'Place dirs in the treeview and files in the listview
Dim sFTPFiles() As String
    Select Case status
        Case "DIR"
            'clear the listview
            LstFtpFiles.clear
            DoEvents ' time to clear the listview
            status = Trim("")
            MsgBox StrData
            If Len(StrData) > 0 Then
               sFTPFiles = Split(StrData, vbCrLf)
                Dim i As Integer
                For i = 0 To UBound(sFTPFiles) - 1
                    If Len(sFTPFiles(i)) > 0 Then 'check for 0 len string
                        If InStr(1, sFTPFiles(i), "/") Then 'it is a dir
                            'Put the dir under the selected node
                            'when we create a key we place an _ in front of the key
                            'This is because a key must start with a non numeric
                           MsgBox sFTPFiles(i)
                            Dim oNode As Node
                                Set oNode = trvFtpFldrs.Nodes.Add(trvFtpFldrs.SelectedItem.Key, _
                                tvwChild, _
                                "_" & Left(sFTPFiles(i), Len(sFTPFiles(i)) - 1), _
                                Left(sFTPFiles(i), Len(sFTPFiles(i)) - 1), _
                                "ClosFldr")
                            If Not (oNode Is Nothing) Then
                                oNode.EnsureVisible
                                oNode.Parent.Image = "OpenFldr"
                            End If
                        Else 'it is a file
                            LstFtpFiles.AddItem sFTPFiles(i)
                        End If
                    End If
                Next i
            End If
        Case "CD"
            'we changed dirs so list any files and subdirs located in the selected dir
            status = "DIR"
            'Inet1.Execute , "PWD"
            Inet1.Execute , "DIR" 'if the dir is empty it could take a while for this to complete
        Case "REN"
            ' do a Dir so you can see that the file name did change
            status = "DIR"
            Inet1.Execute , "DIR"
        Case "DEL"
            ' do a Dir so you can see that the file was deleted
            status = "DIR"
            Inet1.Execute , "DIR"
        Case "GET"
            status = Trim("")
            'update the file control to show the file
            'FlsLst.Refresh
        Case "PUT"
            'we want to do a dir to show the file is now there
            status = "DIR"
            Inet1.Execute , "DIR"
        Case "DEL"
            'we want to do a dir to show that the file is gone
            status = "DIR"
            Inet1.Execute , "DIR"
        Case "REN"
            'we want to do (DIR) to show the new file name
            status = "DIR"
            Inet1.Execute , "DIR"
        Case "MKDIR"
            'we want to do (dir) to show the new Dir
            status = "DIR"
            Inet1.Execute , "DIR"
    End Select
Exit Sub
MyErr:
    If err.Number = 35602 Then
        Resume Next
    Else
        MsgBox str(err.Number) & ": " & err.Description, vbOKOnly, "Error"
    End If
End Sub
Private Sub trvFtpFldrs_DblClick()
    If Inet1.URL = Trim("") Then
        Beep
        LblStatus.Caption = ("Status : Not Connected")
        Exit Sub
    End If
    If Inet1.StillExecuting Then
        LblStatus.Caption = "Still working on last request! Please try again"
        Exit Sub
    End If
    
    status = "CD"
    If Trim(trvFtpFldrs.SelectedItem.Key) = "ROOT" Then
    trvFtpFldrs.Nodes.clear
    trvFtpFldrs.Nodes.Add , , "ROOT", "Root", "ClosFldr"
    trvFtpFldrs.Nodes("ROOT").Selected = True
    Inet1.Execute , "CD /"
    Else 'not at the root
        Dim bFlag As Boolean
        Dim sTemp As String
        Dim oNode As Node
        bFlag = True
        sTemp = trvFtpFldrs.SelectedItem.Text
        Set oNode = trvFtpFldrs.SelectedItem.Parent
        If oNode.Key = "ROOT" Then 'root node
                sTemp = "/" & sTemp
        Else
            sTemp = oNode.Text & "/" & sTemp
            Do While bFlag
                Set oNode = oNode.Parent
                If oNode.Key = "ROOT" Then 'root node
                    sTemp = "/" & sTemp
                    bFlag = False
                Else
                    sTemp = oNode.Text & "/" & sTemp
                End If
            Loop
        End If
        Inet1.Execute , " CD " & sTemp
    End If

End Sub

Attached File  New Folder.zip (4.96K)
Number of downloads: 34

This post has been edited by modi123_1: 13 September 2012 - 07:20 AM
Reason for edit:: fixed botched code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Problem with FTP

#2 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 572
  • View blog
  • Posts: 2,985
  • Joined: 19-May 09

Re: Problem with FTP

Posted 15 September 2012 - 07:38 PM

Which part of the code that you published do you think might be the cause of your problem? Also, why are you keeping secrets from us if you want us to help? :) Why aren't we allowed to know which files are supposed to display that are not displaying?
Was This Post Helpful? 0
  • +
  • -

#3 maheshsanka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-September 12

Re: Problem with FTP

Posted 16 September 2012 - 12:19 AM

View PostBobRodes, on 15 September 2012 - 07:38 PM, said:

Which part of the code that you published do you think might be the cause of your problem? Also, why are you keeping secrets from us if you want us to help? :) Why aren't we allowed to know which files are supposed to display that are not displaying?

Hi Bob Rodes,

My problem has been solved. This is because of INET contro. So i have used some api functions.Now it is working fine.
I am working on other concept. Once it is completed, i will post my entire code here .so that for future it may be reference to others
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1