Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

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

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

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
martin

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?
glacierlee

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();
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.
martin

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?
glacierlee

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
}
martin

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.
glacierlee

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

I have attached the full session log, please help to take a look, thanks.
martin

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.
glacierlee

I figured out the error was due to an space in the file name, but I have no idea how to resolve it yet.
glacierlee

[.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.