Ftp::GetFileSize does not allowing path with backslash.

+1 vote
asked Jul 29, 2010 by _FRED_ (640 points)
edited Jul 29, 2010

I trying an execute a next code:

  using (var client = new Ftp()) {
    client.Connect("Server");
    client.Login("UserName", "Password");
    var size1 = client.GetFileLength(@"folder/file");
    var size2 = client.GetFileLength(@"folder\file");
  }//using

First, size1, is returned successfully, and second size2 is failed (on some servers) with FtpExceptionStatus.ProtocolError, "Requested action not taken. File doesnot exist (550).".

But, client.GetFile() with a second path is succeed. Do you can to format a path into a canonical form within a Ftp class?

Applies to: Rebex FTP/SSL

1 Answer

+1 vote
answered Jul 29, 2010 by Martin Vobr (12,860 points)
edited Jul 29, 2010
 
Best answer

Problem is that there is no "canonical form" of path in FTP protocol specification. Some FTP servers use only "/", some use only "\". Some allow both of them. And some may use a completely different directory separators.

The safest way is to split directory change and GetFileLength into two separate call.

using (var client = new Ftp()) {
    client.Connect("Server");
    client.Login("UserName", "Password");
    client.ChangeDirectory("folder");
    var size1 = client.GetFileLength("file");
  }//using

UPDATE::

Answer to "why GetFileLength is failed and GetFile no?"

The GetFileLength internally issues the SIZE filename command. The GetFile issues the RETR filename" command. It might be possible that this specific FTP server does support paths with '\' for RETR and doesn't support it for SIZE command.

It looks quite strange. Would it be possible to create a communication log from Rebex component (as described at rebex.net/kb/logging.aspx) and from FileZilla and either update your question or send it to support@rebex.net for analysis?

commented Jul 29, 2010 by _FRED_ (640 points)
Thanks! But, why GetFileLength is failed and GetFile no?
commented Jul 29, 2010 by Martin Vobr (12,860 points)
@_FRED_, I've updated my answer and discussed the GetFileLength and GetFile differences.
...