[C#] 심플한 FTP Library

간단하게 적용할수 있는 FTP 라이브러리다.

아래 셈플 코드로 FTP로 할수있는건 모두 가능하다.

// create an FTP client
FtpClient client = new FtpClient("");

// if you don't specify login credentials, we use the "anonymous" user account
client.Credentials = new NetworkCredential("david", "pass123");

// begin connecting to the server

// get a list of files and directories in the "/htdocs" folder
foreach (FtpListItem item in client.GetListing("/htdocs")) {
  // if this is a file
  if (item.Type == FtpFileSystemObjectType.File){
    // get the file size
    long size = client.GetFileSize(item.FullName);
  // get modified date/time of the file or folder
  DateTime time = client.GetModifiedTime(item.FullName);

  // calculate a hash for the file on the server side (default algorithm)
  FtpHash hash = client.GetHash(item.FullName);

// upload a file
client.UploadFile(@"C:\MyVideo.mp4", "/htdocs/big.txt");

// rename the uploaded file
client.Rename("/htdocs/big.txt", "/htdocs/big2.txt");

// download the file again
client.DownloadFile(@"C:\MyVideo_2.mp4", "/htdocs/big2.txt");

// delete the file

// delete a folder recursively

// check if a file exists
if (client.FileExists("/htdocs/big2.txt")){ }

// check if a folder exists
if (client.DirectoryExists("/htdocs/extras/")){ }

// upload a file and retry 3 times before giving up
client.RetryAttempts = 3;
client.UploadFile(@"C:\MyVideo.mp4", "/htdocs/big.txt", FtpExists.Overwrite, false, FtpVerify.Retry);

// disconnect! good bye!



제작자 Github 링크






Post Author: 김 키티

답글 남기기

이메일 주소를 발행하지 않을 것입니다. 필수 항목은 *(으)로 표시합니다