[.NET Assembly] Invalid number of arguments MLST

Advertisement

glacierlee
Joined:
Posts:
7
Location:
I am who I am

[.NET Assembly] Invalid number of arguments MLST

I am currently using the .NET library to download files from my application. However, I encountered the following issue during the FTP download.

I tried to download the file through FileZilla Client with no problem.

Library Version: 5.9.4
Protocol: FTP
Error message:
Can't get attributes of file '/teck/csv/serials_incremental_27_04_2017 11_43_31.csv'.
Could not retrieve file information
Invalid number of arguments MLST
Anybody can tell me how to fix this error? Thank you.
Last edited by glacierlee on 2017-05-12 03:42; edited 3 times in total
  • ftp.log (7.61 KB, Private file)
Description: Full Session Log

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,453
Location:
Prague, Czechia

Re: [.Net Assembly] Invalid number of arguments MLST

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

martin
Site Admin
martin avatar

Re: [.Net Assembly] Invalid number of arguments MLST

You seem to have tried to quote the path somehow. Did you? What is your code like?

Use just a simple path, no quoting. If that does not work, post a log file for that.

Reply with quote

Advertisement

glacierlee
Joined:
Posts:
7
Location:
I am who I am

Re: [.Net Assembly] Invalid number of arguments MLST

Yes, actually I didn't quote the path initially, but it didn't work. Then I tried to quote the path still no help.

Here is my code after removing the quote, and attached is the log.
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
    HostName = "xxx.xx.xxx.xx",
    UserName = "FTPUser",
    Password = "Password",
    PortNumber = 21,
    Protocol = Protocol.Ftp
};
 
using (Session session = new Session())
{
    try
    {
        // Connect
        session.SessionLogPath = "e:\\temp\\ftp.log";
        session.Open(sessionOptions);
        
        var remoteFileInfos = session.EnumerateRemoteFiles("/Inbox/csv", "*.csv", EnumerationOptions.None)
            .Where(file => !file.IsDirectory)
                .OrderByDescending(file => file.LastWriteTime);
        foreach (var remoteFileInfo in remoteFileInfos)
        {
            var remoteFile = session.EscapeFileMask(String.Format("{0}", remoteFileInfo.FullName));
            var localFile = Path.GetFullPath(String.Format("e:\\temp\\{0}", remoteFileInfo.Name));
            if (!remoteFileInfo.Name.IsNullOrEmpty())
            {
                session.GetFiles(remoteFile, localFile,false).Check();
                var archiveFilePath = session.EscapeFileMask("/Inbox/Backup" + "/" + remoteFileInfo.Name);
                if (session.FileExists(archiveFilePath))
                    session.RemoveFiles(archiveFilePath);
                session.MoveFile(remoteFile, archiveFilePath);
            }
        }
        session.Close();
    }
    catch (Exception ex)
    {
        session.Dispose();//Release session
        txtOutput.Text = $"{ex.Message}\r\n{ex.StackTrace}";
    }
    // Download the selected file
}
  • ftp.log (7.53 KB, Private file)

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,453
Location:
Prague, Czechia

Re: [.Net Assembly] Invalid number of arguments MLST

Your code is correct. I have successfully tested it against couple of servers.

It looks like a server-side problem/incompatibility. FTP commands should require no quoting.

Are you using the latest version of the server?

Reply with quote

glacierlee

Re: [.Net Assembly] Invalid number of arguments MLST

I am not sure, the server is holding by one of our customers.
However, I have tried the .NET FtpWebRequest with no problem.

Reply with quote

Advertisement

glacierlee
Joined:
Posts:
7
Location:
I am who I am

Re: [.Net Assembly] Invalid number of arguments MLST

Sure, below are the codes I tested with FtpWebRequest:
Uri ftpUri = new Uri("ftp://FTPuser@xxx.xx.xxx.xx/Inbox/csv/serials_incremental_27_04_2017 11_43_31.csv");
 
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(ftpUri);
FtpWebResponse ftpResponse = null;
FileStream ftpfile = new FileStream("e:\\temp\\FTP\\serials_incremental_27_04_2017 11_43_31.csv", FileMode.Create);
ftpRequest.Credentials = new NetworkCredential("FTPuser", "Password");
ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
ftpRequest.UseBinary = true;
ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
Stream ftpstream = ftpResponse.GetResponseStream();
 
byte[] ftpbyte = new byte[2048];
int readcout = 0;
readcout = ftpstream.Read(ftpbyte, 0, 2048);
while (readcout > 0)
{
    ftpfile.Write(ftpbyte, 0, readcout);
    readcout = ftpstream.Read(ftpbyte, 0, 2048);
}
 
ftpfile.Close();
ftpResponse.Close();
ftpstream.Close();
  • ftp.log (2.71 KB, Private file)

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,453
Location:
Prague, Czechia

Re: [.Net Assembly] Invalid number of arguments MLST

As you can see in the log, the FtpWebRequest does not quote the path in the RETR command either.
System.Net Information: 0 : [7956] FtpControlStream#61476884 - Sending command [RETR Inbox/csv/serials_incremental_27_04_2017 11_43_31.csv]
What if you set the Method to GetDateTimestamp or GetFileSize?

Reply with quote

glacierlee
Joined:
Posts:
7
Location:
I am who I am

Re: [.Net Assembly] Invalid number of arguments MLST

I tried both methods with no problem. But I get the following error when I tried ListDirectory.
The remote server returned an error: (501) Syntax error in parameters or arguments.
   at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
   at System.Net.CommandStream.Dispose(Boolean disposing)
   at System.IO.Stream.Close()
   at System.Net.ConnectionPool.Destroy(PooledStream pooledStream)
   at System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse)
   at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
   at System.Net.FtpWebRequest.GetResponse()
   at EdiTranslatorTest.frmMain.DownloadFtpByWebRequest() in E:\Work\Development\DOTNET\EDI Hub\Code_NH\EdiTranslatorTest\frmMain.cs:line 187
   at EdiTranslatorTest.frmMain.btnTest_Click(Object sender, EventArgs e) in E:\Work\Development\DOTNET\EDI Hub\Code_NH\EdiTranslatorTest\frmMain.cs:line 40

Reply with quote

martin
Site Admin
martin avatar

Re: [.Net Assembly] Invalid number of arguments MLST

So it's indeed a bug in the server. It behaves inconsistently with different commands.

Reply with quote

Advertisement

You can post new topics in this forum