Session.GetFiles fails with "Can't get attributes of file"
I'm automating WinScp (version 5.1.0.0) from a C# program.
My code works successfully with a number of FTP servers, but fails to download files from an NcFTPd server. Interestingly I can download files via the WinScp GUI without any problems.
A small repro case is below. The call to Session.GetFiles fails with "Can't get attributes of file".
var sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
FtpMode = FtpMode.Passive,
FtpSecure = FtpSecure.None,
HostName = "...",
PortNumber = 21,
UserName = "...",
Password = "..."
};
var transferOptions = new TransferOptions
{
PreserveTimestamp = true,
TransferMode = TransferMode.Binary
};
using (var session = new Session())
{
session.SessionLogPath = "WinScpLog.txt";
session.Open(sessionOptions);
var remoteDirectoryInfo = session.ListDirectory(".");
var firstFileName = remoteDirectoryInfo.Files.First(x => !x.IsDirectory).Name;
session.GetFiles(firstFileName, ".", false).Check();
}
I'll send a full session log by email, but the relevant snippet seems to be as follows:
> 2012-09-27 12:41:04.493 Script: get -nopermissions -preservetime -transfer="binary" -- "SomeFile.txt" "."
. 2012-09-27 12:41:04.494 Listing file "SomeFile.txt".
. 2012-09-27 12:41:04.494 Retrieving file information...
> 2012-09-27 12:41:04.494 MLST SomeFile.txt
< 2012-09-27 12:41:07.786 500 Syntax error, command unrecognized.
. 2012-09-27 12:41:07.786 Could not retrieve file information
< 2012-09-27 12:41:07.786 Script: Can't get attributes of file 'SomeFile.txt'.
< 2012-09-27 12:41:07.787 Script: Could not retrieve file information
< 2012-09-27 12:41:07.787 Syntax error, command unrecognized.
. 2012-09-27 12:41:07.787 Script: Failed
> 2012-09-27 12:41:11.959 Script: exit
. 2012-09-27 12:41:11.959 Script: Exit code: 1
. 2012-09-27 12:41:11.962 Disconnected from server
My code works successfully with a number of FTP servers, but fails to download files from an NcFTPd server. Interestingly I can download files via the WinScp GUI without any problems.
A small repro case is below. The call to Session.GetFiles fails with "Can't get attributes of file".
var sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
FtpMode = FtpMode.Passive,
FtpSecure = FtpSecure.None,
HostName = "...",
PortNumber = 21,
UserName = "...",
Password = "..."
};
var transferOptions = new TransferOptions
{
PreserveTimestamp = true,
TransferMode = TransferMode.Binary
};
using (var session = new Session())
{
session.SessionLogPath = "WinScpLog.txt";
session.Open(sessionOptions);
var remoteDirectoryInfo = session.ListDirectory(".");
var firstFileName = remoteDirectoryInfo.Files.First(x => !x.IsDirectory).Name;
session.GetFiles(firstFileName, ".", false).Check();
}
I'll send a full session log by email, but the relevant snippet seems to be as follows:
> 2012-09-27 12:41:04.493 Script: get -nopermissions -preservetime -transfer="binary" -- "SomeFile.txt" "."
. 2012-09-27 12:41:04.494 Listing file "SomeFile.txt".
. 2012-09-27 12:41:04.494 Retrieving file information...
> 2012-09-27 12:41:04.494 MLST SomeFile.txt
< 2012-09-27 12:41:07.786 500 Syntax error, command unrecognized.
. 2012-09-27 12:41:07.786 Could not retrieve file information
< 2012-09-27 12:41:07.786 Script: Can't get attributes of file 'SomeFile.txt'.
< 2012-09-27 12:41:07.787 Script: Could not retrieve file information
< 2012-09-27 12:41:07.787 Syntax error, command unrecognized.
. 2012-09-27 12:41:07.787 Script: Failed
> 2012-09-27 12:41:11.959 Script: exit
. 2012-09-27 12:41:11.959 Script: Exit code: 1
. 2012-09-27 12:41:11.962 Disconnected from server