[C#] 심플한 FTP Library

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

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

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

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

// begin connecting to the server
client.Connect();

// 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
client.DeleteFile("/htdocs/big2.txt");

// delete a folder recursively
client.DeleteDirectory("/htdocs/extras/");

// 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!
client.Disconnect();

 

다운로드

제작자 Github 링크

 

FluentFTP-master.zip

 

 

 

Post Author: 김 키티

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다