Why doesn't FTPWebRequest or WebRequest accept the /../ path at all?

I am trying to automate some upload / download tasks from an ftp server. When I connect to the server through the client or through Firefox even to get to my directory, I must specify this path:

ftp://ftpserver.com/../AB00000/incoming/files 

If I try to access this:

 ftp://ftpserver.com/AB00000/incoming/files 

The server gives an error message that the directory does not exist. So the problem is:

I am trying to create an FTPWebRequest with the first ftp address, but it always parses the "/../" part, and then my server says that the path does not exist.

I tried these:

  Uri target = new Uri("ftp://ftpserver.com/../AB00000/incoming/files"); FtpWebRequest request = (FtpWebRequest)WebReqeuest.Create(target); 

and

 string target = "ftp://ftpserver.com/../AB00000/incoming/files"; FtpWebRequest request = (FtpWebRequest)WebRequest.Create(target); 

In the first bit, the path is already invalid when an instance of the Uri object is created in the second bit after the WebRequest.Create method. Any ideas what is going on?

EDIT:

Also, since I posted this, I tried to create a URI with the no parse option. I also tried something like this:

 string ftpserver = "ftp://ftpserver.com/../"; string path = "12345/01/01/file.toupload"; Uri = new Uri(ftpserver, path, true); 

And he always parses the root part ("/../").

+3
source share
4 answers

Try to slip away from .. with something like:

 Uri target = new Uri("ftp://ftpserver.com/%2E%2E/AB00000/incoming/files"); 

This works according to this blog , which I found in this discussion .

+10
source

Not sure about this, but it may be for security reasons, since allowing "/../" URIs will potentially allow people to freely navigate any server file system.

In addition, the official RFC URI claims that when resolving the URI, one of the steps taken is actually deleting the "/../" segments, so this is not a problem in the C # library, but the usual behavior of the URI.

+3
source

This FTP file upload in C # .Net user function helped me.

0
source

Have you tried using the @ symbol like that?

 Uri target = new Uri(@"ftp://ftpserver.com/../AB00000/incoming/files"); FtpWebRequest request = (FtpWebRequest)WebReqeuest.Create(target); 
-one
source

All Articles