GetStringResponse - wrong result.

newguy

Well-known member
Joined
Jun 30, 2008
Messages
611
Location
Denver Co, USA
Programming Experience
1-3
I am using FTP and using the ListDirectoryDetails method - in the ResponseString I get back <DIR> for the files so when I parse my FTPFileInfo class for the returned values these show up as directories and not files. This is the parser:
VB.NET:
Sub New(ByVal line As String, ByVal path As String)
    'parse line
    Dim m As Match = GetMatchingRegex(line)
    If m Is Nothing Then
      'failed
      Throw New ApplicationException("Unable to parse line: " & line)
    Else
      _filename = m.Groups("name").Value
      _path = path
      _permission = m.Groups("permission").Value
      Dim _dir As String = m.Groups("dir").Value 
      If (_dir <> "" And _dir <> "-") Then  [COLOR="Red"]'<- is this part right?[/COLOR]
        _fileType = DirectoryEntryTypes.Directory
      Else
        _fileType = DirectoryEntryTypes.File
      End If

      Try
        _fileDateTime = Date.Parse(m.Groups("timestamp").Value)
      Catch ex As Exception
        _fileDateTime = Nothing
      End Try

    End If
End Sub

Here's the result output string
HTML:
10-12-09  12:04PM       <DIR>          filename

What I have found is a diff format altogether :
-rw-rw-rw user1 group 4387 Nov 12 12:20 default.asp <-file
drw-rw-rw user1 group 4387 Nov 12 12:20 Admin <-directory

So here I would just check the first character for 'd' or '-'.
So why do I get such a diff format. The server is windows not unix - which is similar to above.
 
Last edited:
Ok so it was a lesson in recursiveness.
VB.NET:
Private Sub GetFTPDirectories(ByVal ftp As FTPClient, ByVal ftpDir As FTPdirectory, ByVal node As TreeNode, ByVal folder As String)
    ftpDir = ftp.ListDirectoryDetail(folder)
    For Each s As FTPfileInfo In ftpDir.GetDirectories()
      If s.FileType = FTPfileInfo.DirectoryEntryTypes.Directory Then
        Dim dir As New TreeNode
        dir.Text = s.Filename
        node.Nodes.Add(dir)
        Dim f As FTPdirectory = ftp.ListDirectoryDetail(s.Filename)
        GetFTPDirectories(ftp, f, dir, s.Filename)
      End If
    Next
End Sub
Private Sub FTP_OFD_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    ftp = New FTPClient(ftpsite, folder, username, password)
    Dim f As FTPdirectory = ftp.ListDirectoryDetail
    Dim mainNode As New TreeNode
    mainNode.Text = "Directory View"
    tvDirectory.Nodes.Add(mainNode)
    GetFTPDirectories(ftp, f, mainNode, "")
End Sub
 
Back
Top