0 votes
by (900 points)
edited by

ftp.FileExists() returns false when file is present in server.

for following server and scenario like
if i provide full path it returns false
root="/"
file name="!Infoonfilesfound_here.txt"

Ftp ftp = new Ftp();
ftp.Connect("ftp.de.4d.com");    
ftp.Login("username", "password"); 

if (ftp.FileExists("/!_Info_on_files_found_here.txt"))
   Console.WriteLine("FileExists");
else
   Console.WriteLine("File not exists");// return false

and if i provide like this

 if (ftp.FileExists("!_Info_on_files_found_here.txt"))
       Console.WriteLine("FileExists");// return true
    else
       Console.WriteLine("File not exists");

for other server it takes full path and returns correct

same thing happen with GetFileLength() method.

log :
2015-06-30 17:23:16.353 Opening log file.
2015-06-30 17:23:16.473 INFO Ftp(1)[9] Info: Connecting to ftp.de.4d.com:21 using Ftp 4.0.4700.0.
2015-06-30 17:23:16.473 INFO Ftp(1)[9] Info: Using proxy none.
2015-06-30 17:23:20.185 INFO Ftp(1)[9] Response: 220 ftp.4d.com FTP server ready.
2015-06-30 17:23:20.195 INFO Ftp(1)[9] Command: USER username
2015-06-30 17:23:20.456 INFO Ftp(1)[9] Response: 331 Guest login ok, send your complete e-mail address as password.
2015-06-30 17:23:20.458 INFO Ftp(1)[9] Command: PASS *********
2015-06-30 17:23:20.735 INFO Ftp(1)[9] Response: 230-The response 'anonymous' is not valid
2015-06-30 17:23:20.735 INFO Ftp(1)[9] Response: 230-Next time please use your e-mail address as your password
2015-06-30 17:23:20.752 INFO Ftp(1)[9] Response: 230- for example: joe@188-54-87-183.mysipl.com
2015-06-30 17:23:20.752 INFO Ftp(1)[9] Response: 230 Guest login ok, access restrictions apply.
2015-06-30 17:23:20.755 INFO Ftp(1)[9] Command: FEAT
2015-06-30 17:23:21.028 INFO Ftp(1)[9] Response: 211-Supported features:
2015-06-30 17:23:21.028 INFO Ftp(1)[9] Response: REST STREAM
2015-06-30 17:23:21.028 INFO Ftp(1)[9] Response: ADAT
2015-06-30 17:23:21.028 INFO Ftp(1)[9] Response: AUTH
2015-06-30 17:23:21.028 INFO Ftp(1)[9] Response: CCC
2015-06-30 17:23:21.028 INFO Ftp(1)[9] Response: CONF
2015-06-30 17:23:21.028 INFO Ftp(1)[9] Response: ENC
2015-06-30 17:23:21.028 INFO Ftp(1)[9] Response: MIC
2015-06-30 17:23:21.028 INFO Ftp(1)[9] Response: PBSZ
2015-06-30 17:23:21.028 INFO Ftp(1)[9] Response: PROT
2015-06-30 17:23:21.028 INFO Ftp(1)[9] Response: MDTM
2015-06-30 17:23:21.028 INFO Ftp(1)[9] Response: UTF8
2015-06-30 17:23:21.028 INFO Ftp(1)[9] Response: SIZE
2015-06-30 17:23:21.028 INFO Ftp(1)[9] Response: 211 End
2015-06-30 17:23:21.062 INFO Ftp(1)[9] Command: OPTS UTF8 ON
2015-06-30 17:23:21.339 INFO Ftp(1)[9] Response: 200 UTF-8 encoding enabled
2015-06-30 17:23:21.346 INFO Ftp(1)[9] Command: TYPE I
2015-06-30 17:23:21.611 INFO Ftp(1)[9] Response: 200 Type set to I.
2015-06-30 17:23:21.612 INFO Ftp(1)[9] Command: SIZE .
2015-06-30 17:23:21.873 INFO Ftp(1)[9] Response: 550 .: not a plain file.
2015-06-30 17:23:21.873 INFO Ftp(1)[9] Command: SIZE /!Infoonfilesfoundhere.txt
2015-06-30 17:23:22.150 INFO Ftp(1)[9] Response: 550 /!
Infoonfilesfoundhere.txt: not a plain file.

any suggestion
thanks

Applies to: Rebex FTP/SSL
by (900 points)
any suggestion
thanks

1 Answer

+1 vote
by (58.9k points)

There is no direct support for checking of file existence in the FTP protocol. So we "simulate" the method with a number of detections in Rebex.Net.Ftp client. Your FTP server does not support the MLST command so we have to rely on SIZE command to detect whether the file exists (if the server returns a size, then we can suppose that this is a file).

However, your server does not seem to like a full path provided to the SIZE command. So although the file exists at the server, it responds badly if we provide the full path to the SIZE command.

2015-07-01 12:00:17.506 INFO Ftp(2)[1] Command: SIZE /file.txt
2015-07-01 12:00:17.685 INFO Ftp(2)[1] Response: 550 /file.txt: not a plain file.

Whereas it responds correctly when a relative path is provided like this:

2015-07-01 12:03:16.367 INFO Ftp(2)[1] Command: SIZE file.txt
2015-07-01 12:03:16.551 INFO Ftp(2)[1] Response: 213 1024

This is a bug of the server. We suggest you to report it to the server vendor and in the meantime the simple workaround for you is to change into the directory and then only check for file existence using the relative path (which works correctly with the problematic server). So in your case use:

ftp.ChangeDirectory("/");
bool fileExists = ftp.FileExists("!_Info_on_files_found_here.txt");
Console.WriteLine(fileExists);

instead of:

ftp.FileExists("/!_Info_on_files_found_here.txt");
by (58.9k points)
Let me know whether the suggested workaround solves your issue.
by (900 points)
Yes,  I all ready try this solution, its working.
thanks for helping me. (",)
...