2

Closed

ftp.DirectoryExists(destinationPath) always returns true

description

Hi,
 
First of all, thank you for this really usefull library ;).
I've tried to use it in one of my test projects but it seems that ftp.DirectoryExists(destinationPath) always returns true.
Is it a known problem or have I misunderstood something in the use of the library?
 
Thank for your time.
 
Sincerely
Closed Aug 23, 2010 at 4:52 PM by scottmeyer
added fix to source control

comments

Technojo wrote Apr 26, 2010 at 11:08 PM

Same here.

jonmikeli wrote Apr 28, 2010 at 3:02 PM

Hi,

I've spent a couple of minutes trying to find out the problem at ftplib source code.
At the DirectoryExists() method (FTPConnection.cs), why the test to evaluate if the directory has been found is different from a similar test at FileExists() method?
...
if (hFindFile == IntPtr.Zero && Marshal.GetLastWin32Error() != WINAPI.ERROR_NO_MORE_FILES)
            {
                return false;
            }
...

I'm not an expert on WinInet so I'm maybe suggesting wrong solutions :s. But I'd like to understand :).
If the complete test is required, it shouldn't be
...
if (hFindFile == IntPtr.Zero && Marshal.GetLastWin32Error() == WINAPI.ERROR_NO_MORE_FILES)
...
instead of
...
if (hFindFile == IntPtr.Zero && Marshal.GetLastWin32Error() != WINAPI.ERROR_NO_MORE_FILES)
...
?

Thank you for your time and your library ;).

Sincerely

scottmeyer wrote Apr 30, 2010 at 6:01 PM

Yes, you are correct. That is probably the issue. I can't verify it at the moment, but changing the conditional to == instead of != should fix the problem.

emilcardell wrote Jun 12, 2010 at 2:35 PM

This error is haunting me as well. What's the solution?

emilcardell wrote Jun 12, 2010 at 2:54 PM

I've got problem with both file exists and directory exists both always gives me true if I give it a path to a file or a directory.
If I change it to == as suggested I get an error "200 Type set to A 200 Port command successful 550 Directory not found."

How do we fix this? Feels like an important feature to have working.

emilcardell wrote Jun 12, 2010 at 10:24 PM

I solved this one. Maby in a nasty way. But my test works.

Added to FtpConnection.cs:

private bool IsPathDirectory(string path)
    {
        string currentDirectory = GetCurrentDirectory();
        try
        {
            SetCurrentDirectory(path);
            SetCurrentDirectory(currentDirectory);
            return true;
        }
        catch (FtpException e)
        {
            SetCurrentDirectory(currentDirectory);
            return false;
        }
    }
And where directoryExists and FileExist returns true I return IsPathDirectory(path) and inverted for file.
Hope it helps some one.

wrote Jul 28, 2010 at 3:54 PM

wrote Aug 23, 2010 at 4:46 PM

scottmeyer wrote Aug 23, 2010 at 4:46 PM

Added change to source control



** Closed by scottmeyer 8/23/2010 8:46 AM

scottmeyer wrote Aug 23, 2010 at 4:46 PM

Added change to source control

wrote Aug 23, 2010 at 4:52 PM

wrote Feb 22, 2013 at 12:18 AM

wrote May 16, 2013 at 12:03 PM