FTP issue: can get remote ListDirectory but FileExists returns false

Advertisement

MFrench
Joined:
Posts:
4
Location:
London

FTP issue: can get remote ListDirectory but FileExists returns false

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

Reply with quote

Advertisement

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

Re: FTP issue: can get remote ListDirectory but FileExists returns false

MFrench wrote:

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

Advertisement

You can post new topics in this forum