C# CODE를 사용하여 FTP 디렉토리에있는 파일의 수를 계산할 수있는 방법이 있습니까? SSIS를 사용할 수있는 권한이 없으므로 Visual Studio를 사용하여이 작업을 완료해야합니다.C#을 사용하여 FTP 디렉토리의 파일 수를 카운트
-2
A
답변
2
다음 코드를 사용하여,
public static String[] FTPListTree(String FtpUri, String User, String Pass) {
List<String> files = new List<String>();
Queue<String> folders = new Queue<String>();
folders.Enqueue(FtpUri);
while (folders.Count > 0) {
String fld = folders.Dequeue();
List<String> newFiles = new List<String>();
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(fld);
ftp.Credentials = new NetworkCredential(User, Pass);
ftp.UsePassive = false;
ftp.Method = WebRequestMethods.Ftp.ListDirectory;
using (StreamReader resp = new StreamReader(ftp.GetResponse().GetResponseStream())) {
String line = resp.ReadLine();
while (line != null) {
newFiles.Add(line.Trim());
line = resp.ReadLine();
}
}
ftp = (FtpWebRequest)FtpWebRequest.Create(fld);
ftp.Credentials = new NetworkCredential(User, Pass);
ftp.UsePassive = false;
ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
using (StreamReader resp = new StreamReader(ftp.GetResponse().GetResponseStream())) {
String line = resp.ReadLine();
while (line != null) {
if (line.Trim().ToLower().StartsWith("d") || line.Contains(" <DIR> ")) {
String dir = newFiles.First(x => line.EndsWith(x));
newFiles.Remove(dir);
folders.Enqueue(fld + dir + "/");
}
line = resp.ReadLine();
}
}
files.AddRange(from f in newFiles select fld + f);
}
return files.ToArray();
}
당신은 또한 followning 코드를 사용할 수 있습니다 : 당신은 디렉토리에 존재하는 모든 파일이 필요
List<string> strList = new List<string>();
FtpWebRequest fwr = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP));
fwr.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
fwr.Method = WebRequestMethods.Ftp.ListDirectory;
//Can object of type StreamReader as given below
StreamReader sr = new StreamReader(fwr.GetResponse().GetResponseStream());
string str = sr.ReadLine();
while (str != null)
{
strList.Add(str);
str = sr.ReadLine();
}
Console.WriteLine(strList.Count);
관련 문제
- 1. FTP : 원격 기계 디렉토리의 파일 수를 소스 Linux 기계로 가져옵니다.
- 2. php - ftp 디렉토리의 모든 파일?
- 3. perl이있는 폴더의 파일 수를 카운트
- 4. 디렉토리의 파일 수를 기준으로 채우기
- 5. 디렉토리의 파일 수를 계산하는 방법
- 6. FTP 디렉토리의 파일 이름 만 WGET
- 7. bat 파일을 사용하여 FTP 디렉토리의 파일을 반복합니다.
- 8. PHP는 FTP Drop 디렉토리의 파일 처리
- 9. ftp .txt PHP에서 카운트 라인
- 10. 디렉토리의 마지막 X 파일 수를 받으십시오.
- 11. 데이터베이스 디렉토리의 문서 카운트
- 12. 디렉토리의 파일 수를 효율적으로 검색하려면 어떻게해야합니까?
- 13. 특정 디렉토리의 파일 및 폴더 수를 계산하십시오.
- 14. Android - 서버 디렉토리의 파일 수를 계산하십시오.
- 15. 디렉토리의 총 파일 수를 확인하는 효과적인 방법
- 16. 패턴별로 배치 파일을 사용하여 디렉토리의 파일 수를 계산하고 작업 수행
- 17. libcurl을 사용하여 디렉토리의 모든 파일 다운로드
- 18. FTP 및 파일
- 19. bash를 사용하여 경로에있는 디렉토리의 수를 어떻게 계산합니까?
- 20. C을 찾는 ++ 구현()`
- 21. Inno Setup 지정된 파일 확장자를 가진 디렉토리의 파일 수를 확인하십시오.
- 22. 터미널 출력의 라인 수를 카운트
- 23. ftp 디렉토리의 파일과 하위 폴더를 복사하는 FTP 명령
- 24. 카테고리의 기사 수를 카운트
- 25. 점수가있는 요소의 수를 카운트
- 26. 카운트 수를 0으로 나누기
- 27. int의 문자 수를 카운트
- 28. 리눅스에서 탭 문자 수를 카운트
- 29. 파이썬을 사용하여 nifi + runscript 카운트 라인 파일
- 30. cURL을 사용하여 디렉토리의 파일 나열
를? 이것을 참조하십시오 - http://stackoverflow.com/questions/14877237/getting-all-file-names-from-a-folder-using-c-sharp –
나는 파일 이름을 잃지 않는다. 나는 단지 파일의 수를 필요로한다. . – rahul
Google에 연결된 'C# ftp count files'텍스트는 첫 번째 결과로서 완전한 자습서를 제공합니다. 이와 같은 질문을 게시하기 전에 조사를 수행하십시오. 예. 물론 FTP에서 파일 수를 세는 것도 가능합니다. 조사 좀 해봐. – Rob