This project is read-only.


FTPfileInfo constructor support for no size


the constructer of FTPfileInfo is expecting size to be non-blank, but for a directory it is blank hence there is an exception.

does anyone have an elegant fix to this problem? (maybe extend FileInfo to support both files and directories?)

this fixed my problem:
In the constructor for FTPFileInfo, i made the below change.

If ((m.Groups("size").Value.Trim.Length) = 0) Then
_size = 0
_size = CLng(m.Groups("size").Value)
End If
Closed Jul 21, 2008 at 2:35 PM by Quango


Quango wrote Jun 13, 2007 at 8:21 AM

Thanks for the comment, I did consider a simpler option:

_size = CLng(Val(m.Groups("size").Value))

However it is part of the Microsoft.VisualBasic namespace and would probably not work in the C# version, so I think perhaps your version is better.

wrote Jun 13, 2007 at 8:21 AM

wrote Nov 21, 2007 at 9:29 AM

I have added this to the Ftpclient VB version - and copied the approach used in the C# version which looks better to me!

wrote Jul 21, 2008 at 2:35 PM

Resolved with changeset 15142.

dcw119mlt wrote Mar 11, 2010 at 8:53 PM

I solved that problem like this:
            If (IsNumeric(m.Groups("size").Value)) Then
                _size = CLng(m.Groups("size").Value)
                _size = 0
            End If
Also, I found an oddity with the strings returned from an FTP server in response to a request for a directory listing. I got very odd dates. For exampe the ftp server coughed up a date like Dec 9 13:33 and parsed into Mar 11, 2010 at 9:13! I think that the missing year confused the code that parses the dates.

i changed the regular expressions to this:
    Private Shared _ParseFormats As String() = { _
        "(?<dir>[\-d])(?<permission>([\-r][\-w][\-xs]){3})\s+\d+\s+\w+\s+\w+\s+(?<size>\d+)\s+(?<ts1>\w+\s+\d+)\s+(?<ts2>\d{4})\s+(?<name>.+)", _
        "(?<dir>[\-d])(?<permission>([\-r][\-w][\-xs]){3})\s+\d+\s+\d+\s+(?<size>\d+)\s+(?<ts1>\w+\s+\d+)\s+(?<ts2>\d{4})\s+(?<name>.+)", _
        "(?<dir>[\-d])(?<permission>([\-r][\-w][\-xs]){3})\s+\d+\s+\d+\s+(?<size>\d+)\s+(?<ts1>\w+\s+\d+)\s+(?<ts2>\d{1,2}:\d{2})\s+(?<name>.+)", _
        "(?<dir>[\-d])(?<permission>([\-r][\-w][\-xs]){3})\s+\d+\s+\w+\s+\w+\s+(?<size>\d+)\s+(?<ts1>\w+\s+\d+)\s+(?<ts2>\d{1,2}:\d{2})\s+(?<name>.+)", _
        "(?<dir>[\-d])(?<permission>([\-r][\-w][\-xs]){3})(\s+)(?<size>(\d+))(\s+)(?<ctbit>(\w+\s\w+))(\s+)(?<size2>(\d+))\s+(?<ts1>\w+\s+\d+)\s+(?<ts2>\d{2}:\d{2})\s+(?<name>.+)", _
and replaced the date decoder with this:
                Dim tsx, ts1, ts2 As String

                ts1 = m.Groups("ts1").Value
                ts2 = m.Groups("ts2").Value

                tsx = ""

                If (InStr(ts1, "-") <> 0) Then
                    tsx = ts1 & " " & ts2
                    If (InStr(ts2, ":") <> 0) Then
                        tsx = ts1 & " " & CStr(Year(Now)) & " " & ts2
                        tsx = ts1 & " " & ts2
                    End If
                End If

                _fileDateTime = Date.Parse(tsx)
                If (_fileDateTime > Now) Then _fileDateTime = DateAdd(DateInterval.Year, -1, _fileDateTime)

            Catch ex As Exception
                _fileDateTime = Nothing

            End Try
crude and brute force, but it worked well. i am under a bit of a time constraint and had to hack this in as quickly as i could...

i don't want you to construe this note as a complaint. i downloaded this a long time ago when it was just a ftpfileinfo and ftpdirectory class. this works great for traversing directories on ftp servers.

thanks for posting the original code. it is designed well, is easy to use, and offers a great abstraction.

wrote Feb 14, 2013 at 7:48 PM

wrote May 16, 2013 at 10:08 AM

wrote Dec 16, 2017 at 3:14 AM