这个库基于C#和.Net框架,它很好的包装了WININET.DLL的FTP功能,建立了一种有效的与FTP服务器交互的方式。
示例代码:
using(FtpConnectionftp=newFtpConnection("ftpserver","username","password")){ftp.Open();/*OpentheFTPconnection*/ftp.Login();/*Loginusingpreviouslyprovidedcredentials*/if(ftp.DirectoryExists("/incoming"))/*checkthatadirectoryexists*/ftp.SetCurrentDirectory("/incoming");/*changecurrentdirectory*/if(ftp.FileExists("/incoming/file.txt"))/*checkthatafileexists*/ftp.GetFile("/incoming/file.txt",false);/*download/incoming/file.txtasfile.txttocurrentexecutingdirectory,overwriteifitexists*///dosomeprocessingtry{ftp.SetCurrentDirectory("/outgoing");ftp.PutFile(@"c:\localfile.txt","file.txt");/*uploadc:\localfile.txttothecurrentftpdirectoryasfile.txt*/}catch(FtpExceptione){Console.WriteLine(String.Format("FTPError:{0}{1}",e.ErrorCode,e.Message));}foreach(vardirinftp.GetDirectories("/incoming/processed")){Console.WriteLine(dir.Name);Console.WriteLine(dir.CreationTime);foreach(varfileindir.GetFiles()){Console.WriteLine(file.Name);Console.WriteLine(file.LastAccessTime);}}}
评论