FTP的上传和下载,在工作中用到了,就记录下载,应该也是往年哪位大神写的吧,自己在记录一下。

定义属性Properties

  自己言语比较笨拙,注释上写的比较清楚,可以在代码中查看具体意思。

  1         #region Properties
  2 
  3         //FTP请求对象
  4         private FtpWebRequest Request = null;
  5 
  6         //FTP相应对象
  7         private FtpWebResponse Response = null;
  8 
  9         //FTP服务器地址
 10         private Uri _Uri;
 11         /// <summary>
 12         /// FTP服务器地址
 13         /// </summary>
 14         public Uri Uri
 15         {
 16             get
 17             {
 18                 if (_DirectoryPath == "/")
 19                 {
 20                     return _Uri;
 21                 }
 22                 else
 23                 {
 24                     string strUri = _Uri.ToString();
 25                     if (strUri.EndsWith("/"))
 26                     {
 27                         strUri = strUri.Substring(0, strUri.Length - 1);
 28                     }
 29                     return new Uri(strUri + this.DirectoryPath);
 30                 }
 31             }
 32             set
 33             {
 34                 if (value.Scheme != Uri.UriSchemeFtp)
 35                 {
 36                     throw new Exception("FTP地址错误");
 37                 }
 38                 _Uri = new Uri(value.GetLeftPart(UriPartial.Authority));
 39                 _DirectoryPath = value.AbsolutePath;
 40                 if (!_DirectoryPath.EndsWith("/"))
 41                 {
 42                     _DirectoryPath += "/";
 43                 }
 44             }
 45         }
 46 
 47         //当前目录
 48         private string _DirectoryPath;
 49         /// <summary>
 50         /// 当前目录
 51         /// </summary>
 52         public string DirectoryPath
 53         {
 54             get
 55             {
 56                 return _DirectoryPath;
 57             }
 58             set
 59             {
 60                 _DirectoryPath = value;
 61             }
 62         }
 63 
 64         // FTP登录用户
 65         private string _UserName;
 66         /// <summary>
 67         /// FTP登录用户
 68         /// </summary>
 69         public string UserName
 70         {
 71             get
 72             {
 73                 return _UserName;
 74             }
 75             set
 76             {
 77                 _UserName = value;
 78             }
 79         }
 80 
 81         // 错误信息
 82         private string _ErrorMsg;
 83         /// <summary>
 84         /// 错误信息
 85         /// </summary>
 86         public string ErrorMsg
 87         {
 88             get
 89             {
 90                 return _ErrorMsg;
 91             }
 92             set
 93             {
 94                 _ErrorMsg = value;
 95             }
 96         }
 97 
 98         // FTP登录密码
 99         private string _Password;
100         /// <summary>
101         ///  FTP登录密码
102         /// </summary>
103         public string Password
104         {
105             get
106             {
107                 return _Password;
108             }
109             set
110             {
111                 _Password = value;
112             }
113         }
114 
115         // 连接FTP服务器的代理服务
116         private WebProxy _Proxy = null;
117         /// <summary>
118         /// 连接FTP服务器的代理服务
119         /// </summary>
120         public WebProxy Proxy
121         {
122             get
123             {
124                 return _Proxy;
125             }
126             set
127             {
128                 _Proxy = value;
129             }
130         }
131 
132         #endregion
View Code

相关文章:

  • 2021-09-07
  • 2022-02-15
  • 2022-12-23
  • 2021-12-26
  • 2021-06-10
  • 2021-12-17
  • 2021-12-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-04-21
  • 2021-10-18
  • 2021-09-25
相关资源
相似解决方案