1
서버의 지정된 디렉토리 (모든 파일 및 디렉토리)를 완전히 다운로드하는 루틴을 작성해야합니다.C#에서 FTP를 사용하여 여러 파일 다운로드
는 지금은
file1.dll
파일 2와 같은 문제는 내가 ... 파일 및 디렉토리의 목록을 얻을 수 있다는 것입니다
public List<string> GetListOfFiles(string serverPath)
{
List<string> files = new List<string>();
try
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://" + serverPath);
request.Credentials = new NetworkCredential(_domain + "\\" + _username, _password);
request.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
while (line != null)
{
files.Add(line);
line = reader.ReadLine();
}
response.Close();
}
catch (WebException ex)
{
FtpWebResponse response = (FtpWebResponse)ex.Response;
string exMsg = string.Empty;
switch (response.StatusCode)
{
case FtpStatusCode.NotLoggedIn:
exMsg = "wrong username/password";
break;
default:
exMsg = "The server is inaccessible or taking too long to respond.";
break;
}
throw new Exception(exMsg);
}
return files;
}
디렉토리 내용을 나열 루틴 그래서 뭔가가있다. dll
dir1 이름
파일 이름을 나열 할 때 파일 이름과 디렉토리 이름을 구별하는 방법이 있습니까? 깃발처럼?
'ListDirectory'에 의해 반환 된 응답은 표준화되지 않았으며 서버가 실행중인 소프트웨어에 따라 달라질 수 있습니다. 이 때문에 파일에서 디렉토리를 알리는 좋은 방법은 없습니다. – cadrell0