How to check if an FTP directory exists

前端 未结 10 1407
一个人的身影
一个人的身影 2020-12-01 10:26

Looking for the best way to check for a given directory via FTP.

Currently i have the following code:

private bool FtpDirectoryExists(string direct         


        
10条回答
  •  天涯浪人
    2020-12-01 11:04

    I couldn't get this @BillyLogans suggestion to work....

    I found the problem was the default FTP directory was /home/usr/fred

    When I used:

    String directory = "ftp://some.domain.com/mydirectory"
    FtpWebRequest requestDir = (FtpWebRequest)FtpWebRequest.Create(new Uri(directory));
    

    I found this gets turned into

    "ftp:/some.domain.com/home/usr/fred/mydirectory"
    

    to stop this change the directory Uri to:

    String directory = "ftp://some.domain.com//mydirectory"
    

    Then this starts working.

提交回复
热议问题