Why doesn't FTPWebRequest, or WebRequest in general accept a /../ path?

£可爱£侵袭症+ 提交于 2019-12-05 18:35:26

Try escaping the .. with something like:

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

That works according to this blog which I found in this discussion.

Not really sure about it, but it may be for security reasons, since allowing "/../" URIs would potentially let people navigate freely on any server's file system.

Also, the official URI RFC states that when resolving an URI one of the steps performed is actually the removal of "/../" segments, so it's not a problem in the C# library but it's regular URI behavior.

Have you tried using the @ symbol like so?

Uri target = new Uri(@"ftp://ftpserver.com/../AB00000/incoming/files");
FtpWebRequest request = (FtpWebRequest)WebReqeuest.Create(target);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!