This project is read-only.

GetListing causes 551 Syntax error

Jul 18, 2015 at 7:43 PM
I am accessing bTrade FTP server.

When I execute the following code I get 551 syntax error:

if (ftpClient.DirectoryExists(ftpDownLoadPath))
  //Set the working directory

  // List all files 
  foreach (FtpListItem item in ftpClient.GetListing())

      var destinationPath = string.Format(@"{0}\{1}", localDownloadPath, item.Name);

      using (var ftpStream = ftpClient.OpenRead(item.Name))
      using (var fileStream = File.Create(destinationPath, (int)ftpStream.Length))
          var buffer = new byte[8 * 1024];
          int count;
          while ((count = ftpStream.Read(buffer, 0, buffer.Length)) > 0)
              fileStream.Write(buffer, 0, count);

          // Delete the file 

    statusMsg.AppendLine("Error FTP Server Directory does not exist:  " + localDownloadPath);

From the Log, I see the following commands sent to the FTP server:
250 CWD command successful.
257 "/inbox" is current directory
200 Type set to I.
227 Entering Passive Mode (160,83,77,210,239,26)
LIST /inbox              __<<<<<< LIST includes the working directory__
551 Syntax error.
Disposing FtpClient object...
221 Goodbye.
Disposing FtpSocketStream...
I can successfully access and list files with the FileZilla FTP client. When it requests a listing for the current directory, it simply executes LIST without a directory.
Status: Connection established, waiting for welcome message...
Response:   220 SecurePortal2000 FTP_Mailbox Server Build 3.2 ready. 20150718143118
Command:    USER ACCITG
Response:   331 Password required.
Command:    PASS *************
Response:   230 Login successful.
Status: Server does not support non-ASCII characters.
Status: Connected
Status: Retrieving directory listing...
Command:    CWD /inbox
Response:   250 CWD command successful.
Command:    TYPE I
Response:   200 Type set to I.
Command:    PASV
Response:   227 Entering Passive Mode (160,83,77,210,240,50)
Command:    LIST   __<<<<<< LIST does not include the working directory__
Response:   150 Opening BINARY mode data connection.
Response:   226 Transfer complete.
Status: Directory listing successful
I had a similar issue with uploading a file. I had to pass only the file name to OpenWrite() for the server to accept it. If I included the path/file in OpenWrite() I got the same error.

Is there any way to issue GetListing() so that a LIST without a directory is executed?

Any suggestions are welcome.

Jul 18, 2015 at 10:51 PM
Bruce, there's not a way to do this without modification the code, that I recall. Been a while since I worked on this project so I may be wrong. Making the changes yourself should be pretty straight forward in the GetListing() method of FtpClient.cs. Let me know if you have any questions.
Jul 19, 2015 at 5:58 PM
The latest commit includes a new untested FtpListOption.NoPath flag you can pass to GetListing() to omit sending a path argument. Let me know if it works, I've not tested it all, just added it and made sure the code builds.
Jul 27, 2015 at 11:09 PM
Thanks I will try it out. I had already customized, but I'll try out the no folder option.