Re: [.Net Assembly] Invalid number of arguments MLST
So it's indeed a bug in the server. It behaves inconsistently with different commands.
Before posting, please read how to report bug or request support effectively.
Bug reports without an attached log file are usually useless.
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
As you can see in the log, theFtpWebRequest
does not quote the path in theRETR
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 theMethod
toGetDateTimestamp
orGetFileSize
?
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]
Method
to GetDateTimestamp
or GetFileSize
?
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();
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?
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
//Protocol = site.Type == "FTP" ? Protocol.Ftp : Protocol.Sftp,
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())
{
//var transOptions = new TransferOptions();
//transOptions.FileMask = remoteFileInfo.Name;
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
}
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.
Please attach a full session log file showing the problem (using the latest version of WinSCP).
To generate the session log file, setSession.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.
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.