using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Globalization;
using System.Text.RegularExpressions;
namespace System.Net.Ftp
{
/// <summary>
/// FTP處理操作類
/// 功能:
/// 下載文件
/// 上傳文件
/// 上傳文件的進度信息
/// 下載文件的進度信息
/// 刪除文件
/// 列出文件
/// 列出目錄
/// 進入子目錄
/// 退出當前目錄返回上一層目錄
/// 判斷遠程文件是否存在
/// 判斷遠程文件是否存在
/// 刪除遠程文件
/// 建立目錄
/// 刪除目錄
/// 文件(目錄)改名
/// </summary>
#region 文件信息結構
public struct FileStruct
{
public string Flags;
public string Owner;
public string Group;
public bool IsDirectory;
public DateTime CreateTime;
public string Name;
}
public enum FileListStyle
{
UnixStyle,
WindowsStyle,
Unknown
}
#endregion
public class clsFTP
{
#region 屬性信息
/// <summary>
/// FTP請求對象
/// </summary>
FtpWebRequest Request = null;
/// <summary>
/// FTP響應對象
/// </summary>
FtpWebResponse Response = null;
/// <summary>
/// FTP服務器地址
/// </summary>
private Uri _Uri;
/// <summary>
/// FTP服務器地址
/// </summary>
public Uri Uri
{
get
{
if (_DirectoryPath == "/")
{
return _Uri;
}
else
{
string strUri = _Uri.ToString();
if (strUri.EndsWith("/"))
{
strUri = strUri.Substring(0, strUri.Length - 1);
}
return new Uri(strUri + this.DirectoryPath);
}
}
set
{
if (value.Scheme != Uri.UriSchemeFtp)
{
throw new Exception("Ftp 地址格式錯誤!");
}
_Uri = new Uri(value.GetLeftPart(UriPartial.Authority));
_DirectoryPath = value.AbsolutePath;
if (!_DirectoryPath.EndsWith("/"))
{
_DirectoryPath += "/";
}
}
}
/// <summary>
/// 當前工作目錄
/// </summary>
private string _DirectoryPath;
/// <summary>
/// 當前工作目錄
/// </summary>
public string DirectoryPath
{
get { return _DirectoryPath; }
set { _DirectoryPath = value; }
}
/// <summary>
/// FTP登錄用戶
/// </summary>
&n