Unable to rename file with ftp methods when current user directory is different from root

后端 未结 2 857
忘了有多久
忘了有多久 2020-12-16 20:00

Remark: due to spam prevention mechanizm I was forced to replace the beginning of the Uris from ftp:// to ftp.

I\'ve got following problem. I have to upload file wit

2条回答
  •  抹茶落季
    2020-12-16 20:19

    I have encountered a similar issue. The problem is that FtpWebRequest (incorrectly) prepends '/' to rename requests, as can be seen from this log (upload & rename):

    URL: 
      http://127.0.0.1/Test.txt
    FTP log:
      STOR Test.txt.part
      RNFR /Test.txt.part
      RNTO /Test.txt
    

    Please note that this problem occurs only when you are uploading to the root directory. If you changed the URL to http://127.0.0.1/path/Test.txt, then everything would work fine.

    My solution to this problem is to use %2E (dot) as the path:

    URL:
      http://127.0.0.1/%2E/Test.txt
    FTP log:
     STOR ./Test.txt.part
     RNFR ./Test.txt.part
     RNTO ./Test.txt
    

    You have to url-encode the dot, otherwise FtpWebRequest would simplify the path "/./" to "/".

提交回复
热议问题