Topic "FTP issue: can get remote ListDirectory but FileExists returns false"

Author Message
MFrench
[View user's profile]

Joined: 2017-01-31
Posts: 4
Location: London
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:

Code:

        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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26504
Location: Prague, Czechia
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.
MFrench
[View user's profile]

Joined: 2017-01-31
Posts: 4
Location: London
Hi,

Thank you for your answer - unfortunately I didn't get the email notification warning me that you had answered.

After searching a bit more, I found a thread in which the same issue was reported.

I've attached the log there:
https://winscp.net/forum/viewtopic.php?p=76366#76366
Advertisements

You can post new topics in this forum






Search

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License