GetListing gets 550 The specified path is invalid

Jun 18, 2013 at 12:57 PM
I'm trying a recursive listing. But when calling GetListing in a subdirectory the tracelistener writes the following line into the log (html/BDF hatml is the first folder and BDF the subdirectory):

MDTM html/BDF
550 The specified path is invalid.

It works on my machine but not on our customers.
Coordinator
Jun 18, 2013 at 1:06 PM
MDTM typically doesn't work on directories, only files. Other than that caveat I really can't tell you anything based on those 2 lines other than the server doesn't like the path or doesn't like that you're trying to get the modification time of a directory. If the modification time of directories is important you need to use a server that implements the MLSD command which typically returns that data in the listing.
Jun 18, 2013 at 1:17 PM
Edited Jun 18, 2013 at 1:18 PM
How do I do it with MLSD.

Now I'm doing a connect this way:
    private FtpClient Connect()
    {
        FtpClient client = new FtpClient();
        client.Host = serverUrl;
        client.Port = 21;
        client.Credentials = new NetworkCredential(user, password);
        client.EncryptionMode = FtpEncryptionMode.None;
        client.DataConnectionType = connectionType;

        return client;
    }
and calling a getlisting this way:
FtpListItem[] list = client.GetListing(path, FtpListOption.Modify);
I need the modification time of the files in the folder.
Coordinator
Jun 18, 2013 at 1:24 PM
If the server supports MLSD it will automatically use it over LIST unless you force otherwise with FtpListOption flags. Read the documentation page on this site which covers the details on file listings and how to get the best results. Long story short is that any server that doesn't support MLSD is up in the the air; there is no standard formatting for LIST and the parsers may or may not work, there is no 100% solution provided here for LIST formats. Dates are ignored in LIST formats when pass the FtpListOption.Modify flag because they are not accurate representations of the time, so MDTM is used instead. As you see, MDTM doesn't work for directories on most servers. MLSD however does have a standard specification and is the fastest and best solution for getting a directory listing along with facts such as size and modification times about the objects in the directory.
Jun 18, 2013 at 1:34 PM
Ok I'm not quite sure what to do and where to set the MLSD-Mode.

In documentation on FtpListOption I found that when using the flag FtpListOption.Modify I put it in MDTM-Mode.
Do I use MLSD-Mode when using FtpListOption.SizeModify instead?
Coordinator
Jun 18, 2013 at 1:39 PM
No, you have to connect to a server that supports MLSD. If the server supports MLSD it will be used, if it doesn't support MLSD it won't be used. It's dependent on the server, there is no flag you can pass that will make the server support MLSD. If the server doesn't support MLSD and you need MLSD then you need to change the FTP server software to one that supports MLSD. Compare the transaction logs between your test environment that worked and the transaction log between the clients that isn't working, specifically look at the response to FEAT and look at the format of the file listings the server sent back when you called GetListing(). That should make it clear what the difference is.
Jun 18, 2013 at 1:43 PM
Edited Jun 18, 2013 at 1:43 PM
Ok now I'm getting the ServerCapabilities from the customers ftp. MDTM is usable. My command should work then, right?

TryConnect - Success - ServerCapabilities: SIZE, MDTM, REST, UTF8

The TraceListener shows hat IIS-Ftp is used.
Software: Microsoft Internet Information Services 7.0

The FEAT-line shows the following, but I don't know what you can see there:
FEAT - 211 0 0 beb53966-151d-4261-9fcb-1da5c404de62 -
Coordinator
Jun 18, 2013 at 2:08 PM
If you want any more help on this matter post the full transaction log from the client per the instructions in Examples\Debug.cs because I'm tired of repeating myself and I don't have a magic 8 ball that can tell me what's wrong.
Jun 18, 2013 at 2:19 PM
Edited Jun 18, 2013 at 3:16 PM
Sorry don't want to bother you. I'm really glad about you help. The TraceListener log up until the listing (including the listing commands):
220 Microsoft FTP Service
USER FTPReplika
331 Password required for FTPReplika.
PASS <omitted>
230 User logged in.
FEAT
211-Extended features supported:
 LANG EN*
 UTF8
 AUTH TLS;TLS-C;SSL;TLS-P;
 PBSZ
 PROT C;P;
 CCC
 HOST
 SIZE
 MDTM
 REST STREAM
211 END
OPTS UTF8 ON
200 OPTS UTF8 command successful - UTF8 encoding now ON.
QUIT
221 Goodbye.
220 Microsoft FTP Service
USER FTPReplika
331 Password required for FTPReplika.
PASS <omitted>
230 User logged in.
FEAT
211-Extended features supported:
 LANG EN*
 UTF8
 AUTH TLS;TLS-C;SSL;TLS-P;
 PBSZ
 PROT C;P;
 CCC
 HOST
 SIZE
 MDTM
 REST STREAM
211 END
OPTS UTF8 ON
200 OPTS UTF8 command successful - UTF8 encoding now ON.
PWD
257 "/" is current directory.
CWD html
250 CWD command successful.
CWD /
250 CWD command successful.
220 Microsoft FTP Service
USER FTPReplika
331 Password required for FTPReplika.
PASS <omitted>
230 User logged in.
FEAT
211-Extended features supported:
 LANG EN*
 UTF8
 AUTH TLS;TLS-C;SSL;TLS-P;
 PBSZ
 PROT C;P;
 CCC
 HOST
 SIZE
 MDTM
 REST STREAM
211 END
OPTS UTF8 ON
200 OPTS UTF8 command successful - UTF8 encoding now ON.
TYPE I
200 Type set to I.
PORT 10,9,12,214,216,135
200 PORT command successful.
LIST html
125 Data connection already open; Transfer starting.
05-22-13  04:15PM       <DIR>          BDF
05-22-13  04:15PM       <DIR>          css
05-22-13  04:15PM       <DIR>          images
01-09-13  11:40AM       <DIR>          legal
05-22-13  04:15PM       <DIR>          media
01-09-13  11:40AM       <DIR>          sounds
226 Transfer complete.
MDTM html/BDF
550 The specified path is invalid. 
MDTM html/css
550 The specified path is invalid. 
MDTM html/images
550 The specified path is invalid. 
MDTM html/legal
550 The specified path is invalid. 
MDTM html/media
550 The specified path is invalid. 
MDTM html/sounds
550 The specified path is invalid. 
Jun 18, 2013 at 2:22 PM
Edited Jun 18, 2013 at 2:22 PM
The code works like this (copied and remove some lines for easier reading):
private void GetFileListingRecursivly(string path)
{

FtpListItem[] list = client.GetListing(path, FtpListOption.Modify);

 foreach (FtpListItem item in list)
 {
    if (item.Type == FtpFileSystemObjectType.Directory)
    {
          List<FtpListItem> subListItems = GetFileListingRecursivly(item.FullName);
     }
 }
}
Coordinator
Jun 18, 2013 at 3:03 PM
Edited Jun 18, 2013 at 3:04 PM
I've done some cleanup in GetListing() to ensure that MDTM is not called when it's not needed. IIS DOS style listings should already include the modification time so there is no need to call MDTM at all. That doesn't change the fact that MDTM doesn't work against directories, what it means is you shouldn't see a call to MDTM at all when running against your client's IIS server. Please get the latest revision and test it, let me know the results. If you have to paste the transaction log again do it as code formatting so that white space is preserved.

-- edit --

I've also tested against Microsoft public IIS server, everything looked good over here.
Jun 18, 2013 at 3:10 PM
Thanks for that. I'll test it and will come back.
Jun 27, 2013 at 8:24 AM
Today I got an answer from the customer.

I changed the code like you described it in an article on codeproject (http://www.codeproject.com/script/Articles/ArticleVersion.aspx?aid=10968&av=599620).
And that worked. So I can not tell if your change worked or not.

But thanks anyway. This project rocks!!!
Coordinator
Jun 27, 2013 at 12:37 PM
That's great news, glad it worked out.