C#的FTP類庫:C# FTP Library
這個類庫對wininet.dll進行封裝提供了 FTP 功能。使用C#語言和.NET框架建立一個與FTP服務器有效的交互方式。示例代碼:
using (FtpConnection ftp = new FtpConnection("ftpserver", "username", "password"))
{
ftp.Open(); /* Open the FTP connection */
ftp.Login(); /* Login using previously provided credentials */
if (ftp.DirectoryExists("/incoming")) /* check that a directory exists */
ftp.SetCurrentDirectory("/incoming"); /* change current directory */
if (ftp.FileExists("/incoming/file.txt")) /* check that a file exists */
ftp.GetFile("/incoming/file.txt", false); /* download /incoming/file.txt as file.txt to current executing directory, overwrite if it exists */
//do some processing
try
{
ftp.SetCurrentDirectory("/outgoing");
ftp.PutFile(@"c:\localfile.txt", "file.txt"); /* upload c:\localfile.txt to the current ftp directory as file.txt */
}
catch (FtpException e)
{
Console.WriteLine(String.Format("FTP Error: {0} {1}", e.ErrorCode, e.Message));
}
foreach(var dir in ftp.GetDirectories("/incoming/processed"))
{
Console.WriteLine(dir.Name);
Console.WriteLine(dir.CreationTime);
foreach (var file in dir.GetFiles())
{
Console.WriteLine(file.Name);
Console.WriteLine(file.LastAccessTime);
}
}
}</pre> <p><strong>項目主頁:</strong><a href="http://www.baiduhome.net/lib/view/home/1371527050218" rel="nofollow" target="_blank">http://www.baiduhome.net/lib/view/home/1371527050218</a></p>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!