一个封装比较完整的FTP类——clsFTP

 

前几天,看见园子里面的博友写了一个支持断点续传的FTP类,一时技痒,干脆写了个更完整的clsFtp类。只是我写这个clsFtp不是支持断点续传的目的,而是为了封装FTP几个基本常用的操作接口。

功能

ü         建立FTP链接

ü         支持代理

ü         多种重载的同步上传文件

ü         多种重载的异步上传文件

ü         多种重载的同步下载文件

ü         多种重载的异步下载文件

ü         上传文件的进度百分比

ü         下载文件的进度白分比

ü         有区分的列出目录或者文件的信息(考虑到MS DOS显示格式和UNIX格式)

ü         目录或文件存在的判断

ü         删除文件

ü         重命名文件、目录

ü         在FTP服务器上面拷贝、移动文件(许多人可能在苦苦寻找这个功能)

ü         建立、删除目录

ü         目录切换操作(很新颖哦 J)

 

公共构造函数

名称

说明

clsFTP()

初始化clsFtp类的新实例

clsFTP(Uri FtpUri, string strUserName, string strPassword)

由FTP地址、FTP登录用户信息、FTP登录用户密码初始化clsFtp类的新实例

clsFTP(Uri FtpUri, string strUserName, string strPassword, WebProxy objProxy)

由FTP地址、FTP登录用户信息、FTP登录用户密码、代理服务器对象初始化clsFtp类的新实例

 

 

 

 

公共属性

名称

说明

Uri

获取或设置FTP服务器地址

DirectoryPath

获取当前工作目录

UserName

获取或设置FTP登录用户

Password

获取或设置FTP登录密码

Proxy

获取或设置连接FTP服务器的代理服务

ErrorMsg

获取操在返回的错误信息

 

 

公共方法

名称

说明

DownloadFile(string RemoteFileName, string LocalPath)

从FTP服务器下载文件,使用与远程文件同名的文件名来保存文件。

参数说明:

RemoteFileName: 远程文件名

LocalPath: 本地路径

DownloadFile(string RemoteFileName, string LocalPath, string LocalFileName)

从FTP服务器下载文件,指定本地路径和本地文件名。

参数说明:

LocalPath: 本地路径

LocalFilePath: 保存文件的本地路径,后面带有"\"

LocalFileName: 保存本地的文件名

DownloadFile(string RemoteFileName)

从FTP服务器下载文件,返回文件二进制数据。

参数说明:

RemoteFileName: 远程文件名

DownloadFileAsync(string RemoteFileName, string LocalPath, string LocalFileName)

从FTP服务器异步下载文件,指定本地路径和本地文件名。

参数说明:

RemoteFileName: 远程文件名       

LocalPath: 保存文件的本地路径,后面带有"\"

LocalFileName: 保存本地的文件名

DownloadFileAsync(string RemoteFileName, string LocalFullPath)

从FTP服务器异步下载文件,指定本地完整路径文件名。

参数说明:

RemoteFileName: 远程文件名

LocalFullPath: 本地完整路径文件名

UploadFile(string LocalFullPath)

上传文件到FTP服务器。

参数说明:

LocalFullPath: 本地带有完整路径的文件名

UploadFile(string LocalFullPath, bool OverWriteRemoteFile)

上传文件到FTP服务器。

参数说明:

LocalFullPath: 本地带有完整路径的文件

OverWriteRemoteFile: 是否覆盖远程服务器上面同名的文件

UploadFile(string LocalFullPath, string RemoteFileName)

上传文件到FTP服务器。

参数说明:

LocalFullPath: 本地带有完整路径的文件

RemoteFileName: 要在FTP服务器上面保存文件名

UploadFile(string LocalFullPath, string RemoteFileName, bool OverWriteRemoteFile)

上传文件到FTP服务器。

参数说明:

LocalFullPath: 本地带有完整路径的文件名

RemoteFileName: 要在FTP服务器上面保存文件名

OverWriteRemoteFile: 是否覆盖远程服务器上面同名的文件

UploadFile(byte[] FileBytes, string RemoteFileName)

上传文件到FTP服务器。

参数说明:

FileBytes: 上传的二进制数据

RemoteFileName: 要在FTP服务器上面保存文件名

UploadFile(byte[] FileBytes, string RemoteFileName, bool OverWriteRemoteFile)

上传文件到FTP服务器。

参数说明:

FileBytes: 文件二进制内容

RemoteFileName: 要在FTP服务器上面保存文件名

OverWriteRemoteFile: 是否覆盖远程服务器上面同名的文件

UploadFileAsync(string LocalFullPath)

异步上传文件到FTP服务器。

参数说明:

LocalFullPath: 本地带有完整路径的文件名

UploadFileAsync(string LocalFullPath, bool OverWriteRemoteFile)

异步上传文件到FTP服务器。

参数说明:

LocalFullPath: 本地带有完整路径的文件

OverWriteRemoteFile: 是否覆盖远程服务器上面同名的文件

UploadFileAsync(string LocalFullPath, string RemoteFileName)

异步上传文件到FTP服务器。

参数说明:

LocalFullPath: 本地带有完整路径的文件

RemoteFileName: 要在FTP服务器上面保存文件名

UploadFileAsync(string LocalFullPath, string RemoteFileName, bool OverWriteRemoteFile)

异步上传文件到FTP服务器。

参数说明:

LocalFullPath: 本地带有完整路径的文件名

RemoteFileName: 要在FTP服务器上面保存文件名

OverWriteRemoteFile: 是否覆盖远程服务器上面同名的文件

UploadFileAsync(byte[] FileBytes, string RemoteFileName)

异步上传文件到FTP服务器。

参数说明:

FileBytes: 上传的二进制数据

RemoteFileName: 要在FTP服务器上面保存文件名

UploadFileAsync(byte[] FileBytes, string RemoteFileName, bool OverWriteRemoteFile)

异步上传文件到FTP服务器。

参数说明:

FileBytes: 文件二进制内容

RemoteFileName: 要在FTP服务器上面保存文件名

OverWriteRemoteFile: 是否覆盖远程服务器上面同名的文件

ListFilesAndDirectories()

列出FTP服务器上面当前目录的所有文件和目录。

ListFiles()

列出FTP服务器上面当前目录的所有文件。

ListDirectories()

列出FTP服务器上面当前目录的所有的目录。

DirectoryExist(string RemoteDirectoryName)

判断当前目录下指定的子目录是否存在。

参数说明:

RemoteDirectoryName: 指定的目录名

FileExist(string RemoteFileName)

判断一个远程文件是否存在服务器当前目录下面。

参数说明:

RemoteFileName: 远程文件名

DeleteFile(string RemoteFileName)

从FTP服务器上面删除一个文件。

参数说明:

RemoteFileName: 远程文件名

ReName(string RemoteFileName, string NewFileName)

更改一个文件的名称或一个目录的名称。

参数说明:

RemoteFileName: 原始文件或目录名称

NewFileName: 新的文件或目录的名称

CopyFileToAnotherDirectory(string RemoteFile, string DirectoryName)

把当前目录下面的一个文件拷贝到服务器上面另外的目录中,注意,拷贝文件之后,当前工作目录还是文件原来所在的目录。

参数说明:

RemoteFile: 当前目录下的文件名

DirectoryName: 新目录名称。

 说明:如果新目录是当前目录的子目录,则直接指定子目录。如: SubDirectory1/SubDirectory2 ;

 如果新目录不是当前目录的子目录,则必须从根目录一级一级的指定。如:./NewDirectory/SubDirectory1/SubDirectory2

MoveFileToAnotherDirectory(string RemoteFile, string DirectoryName)

把当前目录下面的一个文件移动到服务器上面另外的目录中,注意,移动文件之后,当前工作目录还是文件原来所在的目录。

参数说明:

RemoteFile: 当前目录下的文件名

DirectoryName: 新目录名称。

 说明:如果新目录是当前目录的子目录,则直接指定子目录。如: SubDirectory1/SubDirectory2 ;

 如果新目录不是当前目录的子目录,则必须从根目录一级一级的指定。如:./NewDirectory/SubDirectory1/SubDirectory2

MakeDirectory(string DirectoryName)

在FTP服务器上当前工作目录建立一个子目录。

参数说明:

DirectoryName: 子目录名称

RemoveDirectory(string DirectoryName)

从当前工作目录中删除一个子目录。

参数说明:

DirectoryName: 子目录名称

IsValidPathChars(string DirectoryName)

判断目录名中字符是否合法。

参数说明:

DirectoryName: 目录名称

IsValidFileChars(string FileName)

判断文件名中字符是否合法。

参数说明:

FileName: 文件名称

GotoDirectory(string DirectoryName)

进入一个目录。

参数说明:

DirectoryName:

 新目录的名字。

 说明:如果新目录是当前目录的子目录,则直接指定子目录。如: SubDirectory1/SubDirectory2 ;

 如果新目录不是当前目录的子目录,则必须从根目录一级一级的指定。如:./NewDirectory/SubDirectory1/SubDirectory2

EnterOneSubDirectory(string DirectoryName)

从当前工作目录进入一个子目录。

参数说明:

DirectoryName: 子目录名称

ComeoutDirectory()

从当前工作目录往上一级目录。

 

 

 

公共事件

名称

说明

DownloadProgressChanged

异步下载进度发生改变触发的事件

DownloadDataCompleted

异步下载文件完成之后触发的事件

UploadProgressChanged

异步上传进度发生改变触发的事件

UploadFileCompleted

异步上传文件完成之后触发的事件

 

 

 

其他说明

序号

说明

1

支持代理服务器。

可以显式地给Proxy属性赋值;也可以在构造函数中传递Proxy对象。如果代理需要登录用户和密码,则设置Proxy的Credentials属性,例如:

Proxy.Credentials = new NetworkCredential(UserName, Password)

如果没有代理,则无需给Proxy属性赋值或者在构造函数中无需传递Proxy参数。

2

下载文件和上传文件大小最大受Int32.MaxValue限制,所以最大处理只能是2,147,483,647字节。如果您想处理更大的文件,请自己修改代码中对文件打开和读写操作部分的代码使其适应您的要求。

3

只有在异步上传文件或者异步下载文件的时候,才支持进度百分比触发事件和下载(上传)完成事件。

4

由于服务器未发送文件大小,因此被动 FTP 文件传输总是将进度百分比显示为零。若要显示进度,可以通过重写 GetWebRequest 虚拟方法来将 FTP 连接更改为活动状态。所以,我们在clsFTP类中另外使用内部类MyWebClient

 

5

在列出文件和目录的时候,clsFTP类区分出了所获得的响应数据哪些是文件,哪些是目录。同时,考虑到了FTP服务器上面目录样式为MS DOS和UNIX两种表现形式的不同。

6

支持在FTP服务器上面不同目录之间移动文件和拷贝文件的功能。移动文件的方法比较巧妙,只是拷贝文件所使用的方法不太理想。

 

 

 

 

 clsFTP类代码:

None.gif using  System;
None.gif using  System.Collections.Generic;
None.gif using  System.Text;
None.gif using  System.Net;
None.gif using  System.IO;
None.gif using  System.Globalization;
None.gif using  System.Text.RegularExpressions;
None.gif
None.gif namespace  System.Net.Ftp
ExpandedBlockStart.gifContractedBlock.gif dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
InBlock.gif    /// FTP处理操作类
InBlock.gif    /// 功能:
InBlock.gif    /// 下载文件
InBlock.gif    /// 上传文件
InBlock.gif    /// 上传文件的进度信息
InBlock.gif    /// 下载文件的进度信息
InBlock.gif    /// 删除文件
InBlock.gif    /// 列出文件
InBlock.gif    /// 列出目录
InBlock.gif    /// 进入子目录
InBlock.gif    /// 退出当前目录返回上一层目录
InBlock.gif    /// 判断远程文件是否存在
InBlock.gif    /// 判断远程文件是否存在
InBlock.gif    /// 删除远程文件    
InBlock.gif    /// 建立目录
InBlock.gif    /// 删除目录
InBlock.gif    /// 文件(目录)改名
InBlock.gif
InBlock.gif    /// </summary>
InBlock.gif    /// <remarks>
InBlock.gif    /// 创建人:南疯
InBlock.gif    /// 创建时间:2007年4月28日
ExpandedSubBlockEnd.gif    /// </remarks>

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif    文件信息结构#region 文件信息结构
InBlock.gif    public struct FileStruct
ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
InBlock.gif        public string Flags;
InBlock.gif        public string Owner;
InBlock.gif        public string Group;
InBlock.gif        public bool IsDirectory;
InBlock.gif        public DateTime CreateTime;
InBlock.gif        public string Name;
ExpandedSubBlockEnd.gif    }

InBlock.gif    public enum FileListStyle
ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
InBlock.gif        UnixStyle,
InBlock.gif        WindowsStyle,
InBlock.gif        Unknown
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif    #endregion

InBlock.gif    public class clsFTP
ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif        属性信息#region 属性信息
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// FTP请求对象
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        FtpWebRequest Request = null;
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// FTP响应对象
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        FtpWebResponse Response = null;
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// FTP服务器地址
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        private Uri _Uri;
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// FTP服务器地址
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        public Uri Uri
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            get
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (_DirectoryPath == "/")
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    return _Uri;
ExpandedSubBlockEnd.gif                }

InBlock.gif                else
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    string strUri = _Uri.ToString();
InBlock.gif                    if (strUri.EndsWith("/"))
ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
InBlock.gif                        strUri = strUri.Substring(0, strUri.Length - 1);
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    return new Uri(strUri + this.DirectoryPath);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            set
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (value.Scheme != Uri.UriSchemeFtp)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("Ftp 地址格式错误!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                _Uri = new Uri(value.GetLeftPart(UriPartial.Authority));
InBlock.gif                _DirectoryPath = value.AbsolutePath;
InBlock.gif                if (!_DirectoryPath.EndsWith("/"))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    _DirectoryPath += "/";
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 当前工作目录
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        private string _DirectoryPath;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 当前工作目录
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        public string DirectoryPath
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gif{ return _DirectoryPath; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            set dot.gif{ _DirectoryPath = value; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// FTP登录用户
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        private string _UserName;
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// FTP登录用户
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        public string UserName
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gif{ return _UserName; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            set dot.gif{ _UserName = value; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 错误信息
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        private string _ErrorMsg;
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 错误信息
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        public string ErrorMsg
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gif{ return _ErrorMsg; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            set dot.gif{ _ErrorMsg = value; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// FTP登录密码
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        private string _Password;
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// FTP登录密码
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        public string Password
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gif{ return _Password; }
ExpandedSubBlockStart.gifContractedSubBlock.gif            set dot.gif{ _Password = value; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 连接FTP服务器的代理服务
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        private WebProxy _Proxy = null;
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 连接FTP服务器的代理服务
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        public WebProxy Proxy
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            get
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                return _Proxy ;
ExpandedSubBlockEnd.gif            }

InBlock.gif            set
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                _Proxy = value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 是否需要删除临时文件
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        private bool _isDeleteTempFile = false;
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 异步上传所临时生成的文件
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        private string _UploadTempFile = "";
ExpandedSubBlockEnd.gif        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        事件#region 事件
InBlock.gif        public delegate void De_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e);
InBlock.gif        public delegate void De_DownloadDataCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e);
InBlock.gif        public delegate void De_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e);
InBlock.gif        public delegate void De_UploadFileCompleted(object sender, UploadFileCompletedEventArgs e);
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 异步下载进度发生改变触发的事件
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        public event De_DownloadProgressChanged DownloadProgressChanged;
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 异步下载文件完成之后触发的事件
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        public event De_DownloadDataCompleted DownloadDataCompleted;
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 异步上传进度发生改变触发的事件
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        public event De_UploadProgressChanged UploadProgressChanged;
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 异步上传文件完成之后触发的事件
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        public event De_UploadFileCompleted UploadFileCompleted;
ExpandedSubBlockEnd.gif        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        构造析构函数#region 构造析构函数
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 构造函数
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="FtpUri">FTP地址</param>
InBlock.gif        /// <param name="strUserName">登录用户名</param>
ExpandedSubBlockEnd.gif        /// <param name="strPassword">登录密码</param>

InBlock.gif        public clsFTP(Uri FtpUri, string strUserName, string strPassword)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            this._Uri = new Uri(FtpUri.GetLeftPart(UriPartial.Authority));
InBlock.gif            _DirectoryPath = FtpUri.AbsolutePath;
InBlock.gif            if (!_DirectoryPath.EndsWith("/"))
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                _DirectoryPath += "/";
ExpandedSubBlockEnd.gif            }

InBlock.gif            this._UserName = strUserName;
InBlock.gif            this._Password = strPassword;
InBlock.gif            this._Proxy = null;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 构造函数
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="FtpUri">FTP地址</param>
InBlock.gif        /// <param name="strUserName">登录用户名</param>
InBlock.gif        /// <param name="strPassword">登录密码</param>
ExpandedSubBlockEnd.gif        /// <param name="objProxy">连接代理</param>

InBlock.gif        public clsFTP(Uri FtpUri, string strUserName, string strPassword, WebProxy objProxy)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            this._Uri = new Uri(FtpUri.GetLeftPart(UriPartial.Authority));
InBlock.gif            _DirectoryPath = FtpUri.AbsolutePath;
InBlock.gif            if (!_DirectoryPath.EndsWith("/"))
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                _DirectoryPath += "/";
ExpandedSubBlockEnd.gif            }

InBlock.gif            this._UserName = strUserName;
InBlock.gif            this._Password = strPassword;
InBlock.gif            this._Proxy = objProxy;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 构造函数
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        public clsFTP()
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            this._UserName = "anonymous";  //匿名用户
InBlock.gif            this._Password = "@anonymous";
InBlock.gif            this._Uri = null;
InBlock.gif            this._Proxy = null;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 析构函数
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        ~clsFTP()
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            if (Response != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                Response.Close();
InBlock.gif                Response = null;
ExpandedSubBlockEnd.gif            }

InBlock.gif            if (Request != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                Request.Abort();
InBlock.gif                Request = null;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        建立连接#region 建立连接
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 建立FTP链接,返回响应对象
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="uri">FTP地址</param>
ExpandedSubBlockEnd.gif        /// <param name="FtpMathod">操作命令</param>

InBlock.gif        private FtpWebResponse Open(Uri uri, string FtpMathod)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                Request = (FtpWebRequest)WebRequest.Create(uri);
InBlock.gif                Request.Method = FtpMathod;
InBlock.gif                Request.UseBinary = true;
InBlock.gif                Request.Credentials = new NetworkCredential(this.UserName, this.Password);
InBlock.gif                if (this.Proxy != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    Request.Proxy = this.Proxy;
ExpandedSubBlockEnd.gif                }

InBlock.gif                return (FtpWebResponse)Request.GetResponse();
ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 建立FTP链接,返回请求对象
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="uri">FTP地址</param>
ExpandedSubBlockEnd.gif        /// <param name="FtpMathod">操作命令</param>

InBlock.gif        private FtpWebRequest OpenRequest(Uri uri, string FtpMathod)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                Request = (FtpWebRequest)WebRequest.Create(uri);
InBlock.gif                Request.Method = FtpMathod;
InBlock.gif                Request.UseBinary = true;
InBlock.gif                Request.Credentials = new NetworkCredential(this.UserName, this.Password);
InBlock.gif                if (this.Proxy != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    Request.Proxy = this.Proxy;
ExpandedSubBlockEnd.gif                }

InBlock.gif                return Request;
ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        下载文件#region 下载文件
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 从FTP服务器下载文件,使用与远程文件同名的文件名来保存文件
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="RemoteFileName">远程文件名</param>
ExpandedSubBlockEnd.gif        /// <param name="LocalPath">本地路径</param>

InBlock.gif        
InBlock.gif        public bool DownloadFile(string RemoteFileName, string LocalPath)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            return DownloadFile(RemoteFileName, LocalPath, RemoteFileName);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 从FTP服务器下载文件,指定本地路径和本地文件名
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="RemoteFileName">远程文件名</param>
InBlock.gif        /// <param name="LocalPath">本地路径</param>
InBlock.gif        /// <param name="LocalFilePath">保存文件的本地路径,后面带有"\"</param>
ExpandedSubBlockEnd.gif        /// <param name="LocalFileName">保存本地的文件名</param>

InBlock.gif        public bool DownloadFile(string RemoteFileName, string LocalPath, string LocalFileName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            byte[] bt = null;
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (!IsValidFileChars(RemoteFileName) || !IsValidFileChars(LocalFileName) || !IsValidPathChars(LocalPath))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("非法文件名或目录名!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                if (!Directory.Exists(LocalPath))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("本地文件路径不存在!");
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                string LocalFullPath = Path.Combine(LocalPath, LocalFileName);
InBlock.gif                if (File.Exists(LocalFullPath))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("当前路径下已经存在同名文件!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                bt = DownloadFile(RemoteFileName);
InBlock.gif                if (bt != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    FileStream stream = new FileStream(LocalFullPath, FileMode.Create);
InBlock.gif                    stream.Write(bt, 0, bt.Length);
InBlock.gif                    stream.Flush();
InBlock.gif                    stream.Close();
InBlock.gif                    return true;
ExpandedSubBlockEnd.gif                }

InBlock.gif                else
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    return false;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 从FTP服务器下载文件,返回文件二进制数据
InBlock.gif        /// </summary>
ExpandedSubBlockEnd.gif        /// <param name="RemoteFileName">远程文件名</param>

InBlock.gif        public byte[] DownloadFile(string RemoteFileName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (!IsValidFileChars(RemoteFileName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("非法文件名或目录名!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                Response = Open(new Uri(this.Uri.ToString() + RemoteFileName), WebRequestMethods.Ftp.DownloadFile);
InBlock.gif                Stream Reader = Response.GetResponseStream();
InBlock.gif
InBlock.gif                MemoryStream mem = new MemoryStream(1024 * 500);
InBlock.gif                byte[] buffer = new byte[1024];
InBlock.gif                int bytesRead = 0;
InBlock.gif                int TotalByteRead = 0;
InBlock.gif                while (true)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    bytesRead = Reader.Read(buffer, 0, buffer.Length);
InBlock.gif                    TotalByteRead += bytesRead;
InBlock.gif                    if (bytesRead == 0)
InBlock.gif                        break;
InBlock.gif                    mem.Write(buffer, 0, bytesRead);
ExpandedSubBlockEnd.gif                }

InBlock.gif                if (mem.Length > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    return mem.ToArray();
ExpandedSubBlockEnd.gif                }

InBlock.gif                else
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    return null;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        异步下载文件#region 异步下载文件
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 从FTP服务器异步下载文件,指定本地路径和本地文件名
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="RemoteFileName">远程文件名</param>        
InBlock.gif        /// <param name="LocalPath">保存文件的本地路径,后面带有"\"</param>
ExpandedSubBlockEnd.gif        /// <param name="LocalFileName">保存本地的文件名</param>

InBlock.gif        public void DownloadFileAsync(string RemoteFileName, string LocalPath, string LocalFileName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            byte[] bt = null;
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (!IsValidFileChars(RemoteFileName) || !IsValidFileChars(LocalFileName) || !IsValidPathChars(LocalPath))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("非法文件名或目录名!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                if (!Directory.Exists(LocalPath))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("本地文件路径不存在!");
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                string LocalFullPath = Path.Combine(LocalPath, LocalFileName);
InBlock.gif                if (File.Exists(LocalFullPath))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("当前路径下已经存在同名文件!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                DownloadFileAsync(RemoteFileName, LocalFullPath);
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 从FTP服务器异步下载文件,指定本地完整路径文件名
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="RemoteFileName">远程文件名</param>
ExpandedSubBlockEnd.gif        /// <param name="LocalFullPath">本地完整路径文件名</param>

InBlock.gif        public void DownloadFileAsync(string RemoteFileName, string LocalFullPath)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (!IsValidFileChars(RemoteFileName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("非法文件名或目录名!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                if (File.Exists(LocalFullPath))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("当前路径下已经存在同名文件!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                MyWebClient client = new MyWebClient();
InBlock.gif
InBlock.gif                client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
InBlock.gif                client.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(client_DownloadFileCompleted);
InBlock.gif                client.Credentials = new NetworkCredential(this.UserName, this.Password);
InBlock.gif                if (this.Proxy != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    client.Proxy = this.Proxy;
ExpandedSubBlockEnd.gif                }

InBlock.gif                client.DownloadFileAsync(new Uri(this.Uri.ToString() + RemoteFileName), LocalFullPath);
ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 异步下载文件完成之后触发的事件
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="sender">下载对象</param>
ExpandedSubBlockEnd.gif        /// <param name="e">数据信息对象</param>

InBlock.gif        void client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            if (DownloadDataCompleted != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                DownloadDataCompleted(sender, e);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 异步下载进度发生改变触发的事件
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="sender">下载对象</param>
ExpandedSubBlockEnd.gif        /// <param name="e">进度信息对象</param>

InBlock.gif        void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            if (DownloadProgressChanged != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                DownloadProgressChanged(sender, e);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        上传文件#region 上传文件
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 上传文件到FTP服务器
InBlock.gif        /// </summary>
ExpandedSubBlockEnd.gif        /// <param name="LocalFullPath">本地带有完整路径的文件名</param>

InBlock.gif        public bool UploadFile(string LocalFullPath)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            return UploadFile(LocalFullPath, Path.GetFileName(LocalFullPath), false);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 上传文件到FTP服务器
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="LocalFullPath">本地带有完整路径的文件</param>
ExpandedSubBlockEnd.gif        /// <param name="OverWriteRemoteFile">是否覆盖远程服务器上面同名的文件</param>

InBlock.gif        public bool UploadFile(string LocalFullPath, bool OverWriteRemoteFile)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            return UploadFile(LocalFullPath, Path.GetFileName(LocalFullPath), OverWriteRemoteFile);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 上传文件到FTP服务器
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="LocalFullPath">本地带有完整路径的文件</param>
ExpandedSubBlockEnd.gif        /// <param name="RemoteFileName">要在FTP服务器上面保存文件名</param>

InBlock.gif        public bool UploadFile(string LocalFullPath, string RemoteFileName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            return UploadFile(LocalFullPath, RemoteFileName, false);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 上传文件到FTP服务器
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="LocalFullPath">本地带有完整路径的文件名</param>
InBlock.gif        /// <param name="RemoteFileName">要在FTP服务器上面保存文件名</param>
ExpandedSubBlockEnd.gif        /// <param name="OverWriteRemoteFile">是否覆盖远程服务器上面同名的文件</param>

InBlock.gif        public bool UploadFile(string LocalFullPath, string RemoteFileName, bool OverWriteRemoteFile)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (!IsValidFileChars(RemoteFileName) || !IsValidFileChars(Path.GetFileName(LocalFullPath)) || !IsValidPathChars(Path.GetDirectoryName(LocalFullPath)))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("非法文件名或目录名!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                if (File.Exists(LocalFullPath))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    FileStream Stream = new FileStream(LocalFullPath, FileMode.Open, FileAccess.Read);
InBlock.gif                    byte[] bt = new byte[Stream.Length];
InBlock.gif                    Stream.Read(bt, 0, (Int32)Stream.Length);   //注意,因为Int32的最大限制,最大上传文件只能是大约2G多一点
InBlock.gif                    Stream.Close();
InBlock.gif                    return UploadFile(bt, RemoteFileName, OverWriteRemoteFile);
ExpandedSubBlockEnd.gif                }

InBlock.gif                else
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("本地文件不存在!");
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 上传文件到FTP服务器
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="FileBytes">上传的二进制数据</param>
ExpandedSubBlockEnd.gif        /// <param name="RemoteFileName">要在FTP服务器上面保存文件名</param>

InBlock.gif        public bool UploadFile(byte[] FileBytes, string RemoteFileName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            if (!IsValidFileChars(RemoteFileName))
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                throw new Exception("非法文件名或目录名!");
ExpandedSubBlockEnd.gif            }

InBlock.gif            return UploadFile(FileBytes, RemoteFileName, false);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 上传文件到FTP服务器
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="FileBytes">文件二进制内容</param>
InBlock.gif        /// <param name="RemoteFileName">要在FTP服务器上面保存文件名</param>
ExpandedSubBlockEnd.gif        /// <param name="OverWriteRemoteFile">是否覆盖远程服务器上面同名的文件</param>

InBlock.gif        public bool UploadFile(byte[] FileBytes, string RemoteFileName, bool OverWriteRemoteFile)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (!IsValidFileChars(RemoteFileName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("非法文件名!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                if (!OverWriteRemoteFile && FileExist(RemoteFileName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("FTP服务上面已经存在同名文件!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                Response = Open(new Uri(this.Uri.ToString() + RemoteFileName), WebRequestMethods.Ftp.UploadFile);
InBlock.gif                Stream requestStream = Request.GetRequestStream();
InBlock.gif                MemoryStream mem = new MemoryStream(FileBytes);
InBlock.gif
InBlock.gif                byte[] buffer = new byte[1024];
InBlock.gif                int bytesRead = 0;
InBlock.gif                int TotalRead = 0;
InBlock.gif                while (true)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    bytesRead = mem.Read(buffer, 0, buffer.Length);
InBlock.gif                    if (bytesRead == 0)
InBlock.gif                        break;
InBlock.gif                    TotalRead += bytesRead;
InBlock.gif                    requestStream.Write(buffer, 0, bytesRead);
ExpandedSubBlockEnd.gif                }

InBlock.gif                requestStream.Close();
InBlock.gif                Response = (FtpWebResponse)Request.GetResponse();
InBlock.gif                mem.Close();
InBlock.gif                mem.Dispose();
InBlock.gif                FileBytes = null;
InBlock.gif                return true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        异步上传文件#region 异步上传文件
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 异步上传文件到FTP服务器
InBlock.gif        /// </summary>
ExpandedSubBlockEnd.gif        /// <param name="LocalFullPath">本地带有完整路径的文件名</param>

InBlock.gif        public void UploadFileAsync(string LocalFullPath)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            UploadFileAsync(LocalFullPath, Path.GetFileName(LocalFullPath), false);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 异步上传文件到FTP服务器
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="LocalFullPath">本地带有完整路径的文件</param>
ExpandedSubBlockEnd.gif        /// <param name="OverWriteRemoteFile">是否覆盖远程服务器上面同名的文件</param>

InBlock.gif        public void UploadFileAsync(string LocalFullPath, bool OverWriteRemoteFile)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            UploadFileAsync(LocalFullPath, Path.GetFileName(LocalFullPath), OverWriteRemoteFile);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 异步上传文件到FTP服务器
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="LocalFullPath">本地带有完整路径的文件</param>
ExpandedSubBlockEnd.gif        /// <param name="RemoteFileName">要在FTP服务器上面保存文件名</param>

InBlock.gif        public void UploadFileAsync(string LocalFullPath, string RemoteFileName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            UploadFileAsync(LocalFullPath, RemoteFileName, false);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 异步上传文件到FTP服务器
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="LocalFullPath">本地带有完整路径的文件名</param>
InBlock.gif        /// <param name="RemoteFileName">要在FTP服务器上面保存文件名</param>
ExpandedSubBlockEnd.gif        /// <param name="OverWriteRemoteFile">是否覆盖远程服务器上面同名的文件</param>

InBlock.gif        public void UploadFileAsync(string LocalFullPath, string RemoteFileName, bool OverWriteRemoteFile)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (!IsValidFileChars(RemoteFileName) || !IsValidFileChars(Path.GetFileName(LocalFullPath)) || !IsValidPathChars(Path.GetDirectoryName(LocalFullPath)))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("非法文件名或目录名!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                if (!OverWriteRemoteFile && FileExist(RemoteFileName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("FTP服务上面已经存在同名文件!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                if (File.Exists(LocalFullPath))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    MyWebClient client = new MyWebClient();
InBlock.gif
InBlock.gif                    client.UploadProgressChanged += new UploadProgressChangedEventHandler(client_UploadProgressChanged);
InBlock.gif                    client.UploadFileCompleted += new UploadFileCompletedEventHandler(client_UploadFileCompleted);
InBlock.gif                    client.Credentials = new NetworkCredential(this.UserName, this.Password);
InBlock.gif                    if (this.Proxy != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
InBlock.gif                        client.Proxy = this.Proxy;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    client.UploadFileAsync(new Uri(this.Uri.ToString() + RemoteFileName), LocalFullPath);
InBlock.gif
ExpandedSubBlockEnd.gif                }

InBlock.gif                else
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("本地文件不存在!");
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 异步上传文件到FTP服务器
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="FileBytes">上传的二进制数据</param>
ExpandedSubBlockEnd.gif        /// <param name="RemoteFileName">要在FTP服务器上面保存文件名</param>

InBlock.gif        public void UploadFileAsync(byte[] FileBytes, string RemoteFileName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            if (!IsValidFileChars(RemoteFileName))
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                throw new Exception("非法文件名或目录名!");
ExpandedSubBlockEnd.gif            }

InBlock.gif            UploadFileAsync(FileBytes, RemoteFileName, false);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 异步上传文件到FTP服务器
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="FileBytes">文件二进制内容</param>
InBlock.gif        /// <param name="RemoteFileName">要在FTP服务器上面保存文件名</param>
ExpandedSubBlockEnd.gif        /// <param name="OverWriteRemoteFile">是否覆盖远程服务器上面同名的文件</param>

InBlock.gif        public void UploadFileAsync(byte[] FileBytes, string RemoteFileName, bool OverWriteRemoteFile)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif
InBlock.gif                if (!IsValidFileChars(RemoteFileName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("非法文件名!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                if (!OverWriteRemoteFile && FileExist(RemoteFileName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("FTP服务上面已经存在同名文件!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                string TempPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Templates);
InBlock.gif                if (!TempPath.EndsWith("\\"))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    TempPath += "\\";
ExpandedSubBlockEnd.gif                }

InBlock.gif                string TempFile = TempPath + Path.GetRandomFileName();
InBlock.gif                TempFile = Path.ChangeExtension(TempFile, Path.GetExtension(RemoteFileName));
InBlock.gif                FileStream Stream = new FileStream(TempFile, FileMode.CreateNew, FileAccess.Write);
InBlock.gif                Stream.Write(FileBytes, 0, FileBytes.Length);   //注意,因为Int32的最大限制,最大上传文件只能是大约2G多一点
InBlock.gif                Stream.Flush();
InBlock.gif                Stream.Close();
InBlock.gif                Stream.Dispose();
InBlock.gif                _isDeleteTempFile = true;
InBlock.gif                _UploadTempFile = TempFile;
InBlock.gif                FileBytes = null;
InBlock.gif                UploadFileAsync(TempFile, RemoteFileName, OverWriteRemoteFile);
InBlock.gif
InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 异步上传文件完成之后触发的事件
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="sender">下载对象</param>
ExpandedSubBlockEnd.gif        /// <param name="e">数据信息对象</param>

InBlock.gif        void client_UploadFileCompleted(object sender, UploadFileCompletedEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            if (_isDeleteTempFile)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (File.Exists(_UploadTempFile))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    File.SetAttributes(_UploadTempFile, FileAttributes.Normal);
InBlock.gif                    File.Delete(_UploadTempFile);
ExpandedSubBlockEnd.gif                }

InBlock.gif                _isDeleteTempFile = false;
ExpandedSubBlockEnd.gif            }

InBlock.gif            if (UploadFileCompleted != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                UploadFileCompleted(sender, e);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 异步上传进度发生改变触发的事件
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="sender">下载对象</param>
ExpandedSubBlockEnd.gif        /// <param name="e">进度信息对象</param>

InBlock.gif        void client_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            if (UploadProgressChanged != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                UploadProgressChanged(sender, e);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        列出目录文件信息#region 列出目录文件信息
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 列出FTP服务器上面当前目录的所有文件和目录
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        public FileStruct[] ListFilesAndDirectories()
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            Response = Open(this.Uri, WebRequestMethods.Ftp.ListDirectoryDetails);
InBlock.gif            StreamReader stream = new StreamReader(Response.GetResponseStream(), Encoding.Default);
InBlock.gif            string Datastring = stream.ReadToEnd();
InBlock.gif            FileStruct[] list = GetList(Datastring);
InBlock.gif            return list;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 列出FTP服务器上面当前目录的所有文件
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        public FileStruct[] ListFiles()
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            FileStruct[] listAll = ListFilesAndDirectories();
InBlock.gif            List<FileStruct> listFile = new List<FileStruct>();
InBlock.gif            foreach (FileStruct file in listAll)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (!file.IsDirectory)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    listFile.Add(file);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            return listFile.ToArray();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 列出FTP服务器上面当前目录的所有的目录
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        public FileStruct[] ListDirectories()
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            FileStruct[] listAll = ListFilesAndDirectories();
InBlock.gif            List<FileStruct> listDirectory = new List<FileStruct>();
InBlock.gif            foreach (FileStruct file in listAll)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (file.IsDirectory)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    listDirectory.Add(file);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            return listDirectory.ToArray();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 获得文件和目录列表
InBlock.gif        /// </summary>
ExpandedSubBlockEnd.gif        /// <param name="datastring">FTP返回的列表字符信息</param>

InBlock.gif        private FileStruct[] GetList(string datastring)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            List<FileStruct> myListArray = new List<FileStruct>();
InBlock.gif            string[] dataRecords = datastring.Split('\n');
InBlock.gif            FileListStyle _directoryListStyle = GuessFileListStyle(dataRecords);
InBlock.gif            foreach (string s in dataRecords)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (_directoryListStyle != FileListStyle.Unknown && s != "")
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    FileStruct f = new FileStruct();
InBlock.gif                    f.Name = "..";
InBlock.gif                    switch (_directoryListStyle)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
InBlock.gif                        case FileListStyle.UnixStyle:
InBlock.gif                            f = ParseFileStructFromUnixStyleRecord(s);
InBlock.gif                            break;
InBlock.gif                        case FileListStyle.WindowsStyle:
InBlock.gif                            f = ParseFileStructFromWindowsStyleRecord(s);
InBlock.gif                            break;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    if (!(f.Name == "." || f.Name == ".."))
ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
InBlock.gif                        myListArray.Add(f);
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            return myListArray.ToArray();
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 从Windows格式中返回文件信息
InBlock.gif        /// </summary>
ExpandedSubBlockEnd.gif        /// <param name="Record">文件信息</param>

InBlock.gif        private FileStruct ParseFileStructFromWindowsStyleRecord(string Record)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            FileStruct f = new FileStruct();
InBlock.gif            string processstr = Record.Trim();
InBlock.gif            string dateStr = processstr.Substring(0, 8);
InBlock.gif            processstr = (processstr.Substring(8, processstr.Length - 8)).Trim();
InBlock.gif            string timeStr = processstr.Substring(0, 7);
InBlock.gif            processstr = (processstr.Substring(7, processstr.Length - 7)).Trim();
InBlock.gif            DateTimeFormatInfo myDTFI = new CultureInfo("en-US", false).DateTimeFormat;
InBlock.gif            myDTFI.ShortTimePattern = "t";
InBlock.gif            f.CreateTime = DateTime.Parse(dateStr + " " + timeStr, myDTFI);
InBlock.gif            if (processstr.Substring(0, 5) == "<DIR>")
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                f.IsDirectory = true;
InBlock.gif                processstr = (processstr.Substring(5, processstr.Length - 5)).Trim();
ExpandedSubBlockEnd.gif            }

InBlock.gif            else
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif                string[] strs = processstr.Split(new char[] dot.gif{ ' ' }, StringSplitOptions.RemoveEmptyEntries);   // true);
InBlock.gif                processstr = strs[1];
InBlock.gif                f.IsDirectory = false;
ExpandedSubBlockEnd.gif            }

InBlock.gif            f.Name = processstr;
InBlock.gif            return f;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 判断文件列表的方式Window方式还是Unix方式
InBlock.gif        /// </summary>
ExpandedSubBlockEnd.gif        /// <param name="recordList">文件信息列表</param>

InBlock.gif        private FileListStyle GuessFileListStyle(string[] recordList)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            foreach (string s in recordList)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (s.Length > 10
InBlock.gif                 && Regex.IsMatch(s.Substring(0, 10), "(-|d)(-|r)(-|w)(-|x)(-|r)(-|w)(-|x)(-|r)(-|w)(-|x)"))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    return FileListStyle.UnixStyle;
ExpandedSubBlockEnd.gif                }

InBlock.gif                else if (s.Length > 8
InBlock.gif                 && Regex.IsMatch(s.Substring(0, 8), "[0-9][0-9]-[0-9][0-9]-[0-9][0-9]"))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    return FileListStyle.WindowsStyle;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            return FileListStyle.Unknown;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 从Unix格式中返回文件信息
InBlock.gif        /// </summary>
ExpandedSubBlockEnd.gif        /// <param name="Record">文件信息</param>

InBlock.gif        private FileStruct ParseFileStructFromUnixStyleRecord(string Record)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            FileStruct f = new FileStruct();
InBlock.gif            string processstr = Record.Trim();
InBlock.gif            f.Flags = processstr.Substring(0, 10);
InBlock.gif            f.IsDirectory = (f.Flags[0] == 'd');
InBlock.gif            processstr = (processstr.Substring(11)).Trim();
InBlock.gif            _cutSubstringFromStringWithTrim(ref processstr, ' ', 0);   //跳过一部分
InBlock.gif            f.Owner = _cutSubstringFromStringWithTrim(ref processstr, ' ', 0);
InBlock.gif            f.Group = _cutSubstringFromStringWithTrim(ref processstr, ' ', 0);
InBlock.gif            _cutSubstringFromStringWithTrim(ref processstr, ' ', 0);   //跳过一部分
ExpandedSubBlockStart.gifContractedSubBlock.gif            string yearOrTime = processstr.Split(new char[] dot.gif{ ' ' }, StringSplitOptions.RemoveEmptyEntries)[2];
InBlock.gif            if (yearOrTime.IndexOf(":") >= 0)  //time
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                processstr = processstr.Replace(yearOrTime, DateTime.Now.Year.ToString());
ExpandedSubBlockEnd.gif            }

InBlock.gif            f.CreateTime = DateTime.Parse(_cutSubstringFromStringWithTrim(ref processstr, ' ', 8));
InBlock.gif            f.Name = processstr;   //最后就是名称
InBlock.gif            return f;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 按照一定的规则进行字符串截取
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="s">截取的字符串</param>
InBlock.gif        /// <param name="c">查找的字符</param>
ExpandedSubBlockEnd.gif        /// <param name="startIndex">查找的位置</param>

InBlock.gif        private string _cutSubstringFromStringWithTrim(ref string s, char c, int startIndex)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            int pos1 = s.IndexOf(c, startIndex);
InBlock.gif            string retString = s.Substring(0, pos1);
InBlock.gif            s = (s.Substring(pos1)).Trim();
InBlock.gif            return retString;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        目录或文件存在的判断#region 目录或文件存在的判断
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 判断当前目录下指定的子目录是否存在
InBlock.gif        /// </summary>
ExpandedSubBlockEnd.gif        /// <param name="RemoteDirectoryName">指定的目录名</param>

InBlock.gif        public bool DirectoryExist(string RemoteDirectoryName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (!IsValidPathChars(RemoteDirectoryName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("目录名非法!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                FileStruct[] listDir = ListDirectories();
InBlock.gif                foreach (FileStruct dir in listDir)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    if (dir.Name == RemoteDirectoryName)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
InBlock.gif                        return true;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                return false;
ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 判断一个远程文件是否存在服务器当前目录下面
InBlock.gif        /// </summary>
ExpandedSubBlockEnd.gif        /// <param name="RemoteFileName">远程文件名</param>

InBlock.gif        public bool FileExist(string RemoteFileName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (!IsValidFileChars(RemoteFileName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("文件名非法!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                FileStruct[] listFile = ListFiles();
InBlock.gif                foreach (FileStruct file in listFile)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    if (file.Name == RemoteFileName)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
InBlock.gif                        return true;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                return false;
ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        删除文件#region 删除文件
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 从FTP服务器上面删除一个文件
InBlock.gif        /// </summary>
ExpandedSubBlockEnd.gif        /// <param name="RemoteFileName">远程文件名</param>

InBlock.gif        public void DeleteFile(string RemoteFileName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (!IsValidFileChars(RemoteFileName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("文件名非法!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                Response = Open(new Uri(this.Uri.ToString() + RemoteFileName), WebRequestMethods.Ftp.DeleteFile);
ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        重命名文件#region 重命名文件
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 更改一个文件的名称或一个目录的名称
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="RemoteFileName">原始文件或目录名称</param>
ExpandedSubBlockEnd.gif        /// <param name="NewFileName">新的文件或目录的名称</param>

InBlock.gif        public bool ReName(string RemoteFileName, string NewFileName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (!IsValidFileChars(RemoteFileName) || !IsValidFileChars(NewFileName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("文件名非法!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                if (RemoteFileName == NewFileName)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    return true;
ExpandedSubBlockEnd.gif                }

InBlock.gif                if (FileExist(RemoteFileName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    Request = OpenRequest(new Uri(this.Uri.ToString() + RemoteFileName), WebRequestMethods.Ftp.Rename);
InBlock.gif                    Request.RenameTo = NewFileName;
InBlock.gif                    Response = (FtpWebResponse)Request.GetResponse();
InBlock.gif
ExpandedSubBlockEnd.gif                }

InBlock.gif                else
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("文件在服务器上不存在!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                return true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        拷贝、移动文件#region 拷贝、移动文件
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 把当前目录下面的一个文件拷贝到服务器上面另外的目录中,注意,拷贝文件之后,当前工作目录还是文件原来所在的目录
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="RemoteFile">当前目录下的文件名</param>
InBlock.gif        /// <param name="DirectoryName">新目录名称。
InBlock.gif        /// 说明:如果新目录是当前目录的子目录,则直接指定子目录。如: SubDirectory1/SubDirectory2 ;
InBlock.gif        /// 如果新目录不是当前目录的子目录,则必须从根目录一级一级的指定。如: ./NewDirectory/SubDirectory1/SubDirectory2
InBlock.gif        /// </param>
ExpandedSubBlockEnd.gif        /// <returns></returns>

InBlock.gif        public bool CopyFileToAnotherDirectory(string RemoteFile, string DirectoryName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            string CurrentWorkDir = this.DirectoryPath;
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                byte[] bt = DownloadFile(RemoteFile);
InBlock.gif                GotoDirectory(DirectoryName);
InBlock.gif                bool Success = UploadFile(bt, RemoteFile, false);
InBlock.gif                this.DirectoryPath = CurrentWorkDir;
InBlock.gif                return Success;
ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                this.DirectoryPath = CurrentWorkDir;
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 把当前目录下面的一个文件移动到服务器上面另外的目录中,注意,移动文件之后,当前工作目录还是文件原来所在的目录
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="RemoteFile">当前目录下的文件名</param>
InBlock.gif        /// <param name="DirectoryName">新目录名称。
InBlock.gif        /// 说明:如果新目录是当前目录的子目录,则直接指定子目录。如: SubDirectory1/SubDirectory2 ;
InBlock.gif        /// 如果新目录不是当前目录的子目录,则必须从根目录一级一级的指定。如: ./NewDirectory/SubDirectory1/SubDirectory2
InBlock.gif        /// </param>
ExpandedSubBlockEnd.gif        /// <returns></returns>

InBlock.gif        public bool MoveFileToAnotherDirectory(string RemoteFile, string DirectoryName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            string CurrentWorkDir = this.DirectoryPath;
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (DirectoryName == "")
InBlock.gif                    return false;
InBlock.gif                if (!DirectoryName.StartsWith("/"))
InBlock.gif                    DirectoryName = "/" + DirectoryName;
InBlock.gif                if (!DirectoryName.EndsWith("/"))
InBlock.gif                    DirectoryName += "/";
InBlock.gif                bool Success = ReName(RemoteFile, DirectoryName + RemoteFile);
InBlock.gif                this.DirectoryPath = CurrentWorkDir;
InBlock.gif                return Success;
ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                this.DirectoryPath = CurrentWorkDir;
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        建立、删除子目录#region 建立、删除子目录
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 在FTP服务器上当前工作目录建立一个子目录
InBlock.gif        /// </summary>
ExpandedSubBlockEnd.gif        /// <param name="DirectoryName">子目录名称</param>

InBlock.gif        public bool MakeDirectory(string DirectoryName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (!IsValidPathChars(DirectoryName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("目录名非法!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                if (DirectoryExist(DirectoryName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("服务器上面已经存在同名的文件名或目录名!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                Response = Open(new Uri(this.Uri.ToString() + DirectoryName), WebRequestMethods.Ftp.MakeDirectory);
InBlock.gif                return true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 从当前工作目录中删除一个子目录
InBlock.gif        /// </summary>
ExpandedSubBlockEnd.gif        /// <param name="DirectoryName">子目录名称</param>

InBlock.gif        public bool RemoveDirectory(string DirectoryName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (!IsValidPathChars(DirectoryName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("目录名非法!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                if (!DirectoryExist(DirectoryName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("服务器上面不存在指定的文件名或目录名!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                Response = Open(new Uri(this.Uri.ToString() + DirectoryName), WebRequestMethods.Ftp.RemoveDirectory);
InBlock.gif                return true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        文件、目录名称有效性判断#region 文件、目录名称有效性判断
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 判断目录名中字符是否合法
InBlock.gif        /// </summary>
ExpandedSubBlockEnd.gif        /// <param name="DirectoryName">目录名称</param>

InBlock.gif        public  bool IsValidPathChars(string DirectoryName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            char[] invalidPathChars = Path.GetInvalidPathChars();
InBlock.gif            char[] DirChar = DirectoryName.ToCharArray();
InBlock.gif            foreach (char C in DirChar)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (Array.BinarySearch(invalidPathChars, C) >= 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    return false;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            return true;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 判断文件名中字符是否合法
InBlock.gif        /// </summary>
ExpandedSubBlockEnd.gif        /// <param name="FileName">文件名称</param>

InBlock.gif        public bool IsValidFileChars(string FileName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            char[] invalidFileChars = Path.GetInvalidFileNameChars();
InBlock.gif            char[] NameChar = FileName.ToCharArray();
InBlock.gif            foreach (char C in NameChar)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (Array.BinarySearch(invalidFileChars, C) >= 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    return false;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            return true;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        目录切换操作#region 目录切换操作
ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 进入一个目录
InBlock.gif        /// </summary>
InBlock.gif        /// <param name="DirectoryName">
InBlock.gif        /// 新目录的名字。 
InBlock.gif        /// 说明:如果新目录是当前目录的子目录,则直接指定子目录。如: SubDirectory1/SubDirectory2 ; 
InBlock.gif        /// 如果新目录不是当前目录的子目录,则必须从根目录一级一级的指定。如: ./NewDirectory/SubDirectory1/SubDirectory2
ExpandedSubBlockEnd.gif        /// </param>

InBlock.gif        public bool GotoDirectory(string DirectoryName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            string CurrentWorkPath = this.DirectoryPath;
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                DirectoryName = DirectoryName.Replace("\\", "/");
ExpandedSubBlockStart.gifContractedSubBlock.gif                string[] DirectoryNames = DirectoryName.Split(new char[] dot.gif{ '/' });
InBlock.gif                if (DirectoryNames[0] == ".")
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    this.DirectoryPath = "/";
InBlock.gif                    if (DirectoryNames.Length == 1)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
InBlock.gif                        return true;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    Array.Clear(DirectoryNames, 0, 1);
ExpandedSubBlockEnd.gif                }

InBlock.gif                bool Success = false;
InBlock.gif                foreach (string dir in DirectoryNames)
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    if (dir != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
InBlock.gif                        Success = EnterOneSubDirectory(dir);
InBlock.gif                        if (!Success)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
InBlock.gif                            this.DirectoryPath = CurrentWorkPath;
InBlock.gif                            return false;
ExpandedSubBlockEnd.gif                        }

ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                return Success;
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                this.DirectoryPath = CurrentWorkPath;
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 从当前工作目录进入一个子目录
InBlock.gif        /// </summary>
ExpandedSubBlockEnd.gif        /// <param name="DirectoryName">子目录名称</param>

InBlock.gif        private bool EnterOneSubDirectory(string DirectoryName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                if (DirectoryName.IndexOf("/") >= 0 || !IsValidPathChars(DirectoryName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    throw new Exception("目录名非法!");
ExpandedSubBlockEnd.gif                }

InBlock.gif                if (DirectoryName.Length > 0 && DirectoryExist(DirectoryName))
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    if (!DirectoryName.EndsWith("/"))
ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
InBlock.gif                        DirectoryName += "/";
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    _DirectoryPath += DirectoryName;
InBlock.gif                    return true;
ExpandedSubBlockEnd.gif                }

InBlock.gif                else
ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
InBlock.gif                    return false;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            catch (Exception ep)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = ep.ToString();
InBlock.gif                throw ep;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
InBlock.gif        /// 从当前工作目录往上一级目录
ExpandedSubBlockEnd.gif        /// </summary>

InBlock.gif        public bool ComeoutDirectory()
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            if (_DirectoryPath == "/")
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                ErrorMsg = "当前目录已经是根目录!";
InBlock.gif                throw new Exception("当前目录已经是根目录!");
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockStart.gifContractedSubBlock.gif            char[] sp = new char[1] dot.gif{ '/' };
InBlock.gif
InBlock.gif            string[] strDir = _DirectoryPath.Split(sp, StringSplitOptions.RemoveEmptyEntries);
InBlock.gif            if (strDir.Length == 1)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                _DirectoryPath = "/";
ExpandedSubBlockEnd.gif            }

InBlock.gif            else
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                _DirectoryPath = String.Join("/", strDir, 0, strDir.Length - 1);
ExpandedSubBlockEnd.gif            }

InBlock.gif            return true;
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        #endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        重载WebClient,支持FTP进度#region 重载WebClient,支持FTP进度
InBlock.gif        internal class MyWebClient : WebClient
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            protected override WebRequest GetWebRequest(Uri address)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                FtpWebRequest req = (FtpWebRequest)base.GetWebRequest(address);
InBlock.gif                req.UsePassive = false;
InBlock.gif                return req;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        #endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/winner/archive/2007/04/28/731582.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值