Hi,
I'm having a problem that I'm finding quite hard to debug and I haven't found any similar listing in the forum.
I'm trying to donwload a file from a FTP site from a very plain cmd line app in c#. Running the code in debug, I can get the remote directory listing fine, I can loop through it, check the file permissions and dates and so on...
But immediately after I try to do a simple "FileExists" check passing the first file found and I get false every single time. You can see on the code below that I've tried both with just name or full name. The files are on the root.
Connecting using the WinSCP interface, I face the same issue: I can view all the files in the remote folder, but when trying to download one by simple "drag and drop" from the right pane to the left, I get an error of access denied. (System Error. Code: 5.)
Connecting with exactly the same credentials using FileZilla, I can copy files without a problem.
My code is as follows:
public void downloadFile(string fileName, string filePath)
{
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
HostName = Properties.Settings.Default.HOST,
PortNumber = int.Parse(Properties.Settings.Default.FTP_PORT),
UserName = Properties.Settings.Default.FTP_USERNAME,
Password = Properties.Settings.Default.FTP_PASSWORD
};
using (Session session = new Session())
{
session.Open(sessionOptions);
RemoteDirectoryInfo directory = session.ListDirectory("/");
bool check = session.FileExists(directory.Files[1].FullName); //RETURNS FALSE
bool check2 = session.FileExists(directory.Files[1].Name); //RETURNS FALSE
// Download files
//TransferOptions transferOptions = new TransferOptions();
//transferOptions.TransferMode = TransferMode.Binary;
//TransferOperationResult transferResult;
//transferResult = session.GetFiles("/abc", filePath, false, transferOptions);
// Throw on any error
//transferResult.Check()
}
I've also tried adding to the sessionOptions the following:
FtpMode = FtpMode.Passive,
FtpSecure = FtpSecure.None
Even though the documentation says these are the defaults when not specified and the FTP server does require passive and no TLS security at all.
I don't know what else to try. Is there any setting that I'm overlooking or anyway I can further debug the problem?
Thanks