This project is read-only.

Issue with List function

May 10, 2015 at 7:21 AM
I'm running into an issue with GetListing from a Java/Unix based FTP server (but it actually runs on top of a Windows server)

The connection and changing directory, and printing out the current working folder works fine. However, the GetListing reports invalid path.

I'm able to do a listing and retrieve files with other tools just fine. (FileZilla, Directory Opus, and Rebex's trial FTP library), so I'm comfortable the location / path is accurate.


Here is the code that throws the error, and below is the debug output.
        string baseFolder = "Alfresco/Sites";
        using (FtpClient conn = new FtpClient())
        {
            Log.Debug("Connecting");

            conn.Host = "192.168.2.192";
            conn.Credentials = new NetworkCredential("name", "password");
            conn.Connect();
            Log.Debug("Connection Successful");

            conn.SetWorkingDirectory(baseFolder);

            Log.Debug(conn.GetWorkingDirectory());

            try
            {
                FtpListItem[] items = conn.GetListing();
                Log.Debug(items.Count());
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message.ToString());
            }

2015-05-09 23:18:47,877 [10] DEBUG ftpClientTest.Program [(null)] - Connecting
InterNetwork: 192.168.2.192
220 FTP server ready
USER bill.swartz
331 User name okay, need password for bill.swartz
PASS <omitted>
230 User logged in, proceed
FEAT
211-Features supported
MFMT
SIZE
UTF8
MLST size*;modify*;create*;type*;unique*;perm*;media-type*;
MLSD
AUTH TLS
211 END
Text encoding: System.Text.UTF8Encoding
OPTS UTF8 ON
200 OPTS UTF8 ON

2015-05-09 23:19:08,800 [10] DEBUG ftpClientTest.Program [(null)] - Connection Successful
2015-05-09 23:19:08,800 [10] DEBUG ftpClientTest.Program [(null)] - AutoPassive
SYST
215 UNIX Type: Java FTP Server
2015-05-09 23:19:08,847 [10] DEBUG ftpClientTest.Program [(null)] - UNIX Type: Java FTP Server

CWD /Alfresco/Sites
250 Requested file action OK
PWD
257 "/Alfresco/Sites"
2015-05-09 23:19:08,911 [10] DEBUG ftpClientTest.Program [(null)] - WorkingDirectory: /Alfresco/Sites
PWD
257 "/Alfresco/Sites"
TYPE I
200 Command OK
EPSV
229 Entering Extended Passive Mode (|||59709|)
InterNetwork: 192.168.2.192
MLSD /Alfresco/Sites
500 Invalid path
2015-05-09 23:19:09,083 [10] ERROR ftpClientTest.Program [(null)] - Invalid path
Disposing FtpClient object...
QUIT
221 Bye
Disposing FtpSocketStream...

I've read other posts and your comments that MLSD on Unix boxes are unreliable, but just wanted to share that I can do the work with other tools, so there must be something different in your code base. Any thoughts, or how could I further debug?

Thanks
Bill
May 10, 2015 at 7:36 AM
Note that I using the ListOption of ForceList, and was able to get a listing fine.

Bill
Jul 23, 2015 at 11:50 PM
If you don't specify any flag options, then I believe it is using the LIST command.

One FTP server I was working with didn't like having the 'LIST -a /path' in the same line. I had to first change the current working directory and do a 'LIST -a' by itself, and then put back the working directory. I changed the GetListing(...) method as follows:
                bool changeDir = (listcmd != "NLST");

                String command = null;
                if (changeDir) {
                    Execute("CWD " + path.GetFtpPath());
                    command = listcmd;
                }
                else
                    command = String.Format("{0} {1}", listcmd, path.GetFtpPath());

                using (FtpDataStream stream = OpenDataStream(command, 0)) {
                    //...
                }

                if (changeDir)
                    Execute("CWD " + pwd); // put back previous working directory
I found using WinSCP to be helpful. Turn on Debug Level 3, and then look at the log file, which contains the commands that are sent.