首页 | 互联网 | IT动态 | IT培训 | Cisco | Windows | Linux | Java | .Net | Oracle | 软件测试 | C/C++ | 嵌入式开发 | 存储世界 | 服务器
网络设备 | IDC | 安全 | 求职招聘 | 数字网校 | 网页设计 | 技术专题 | 电子书下载 | 教学视频 | 网页设计 | 平面设计 | 搜索 | 博客 | 论坛
中国IT实验室Dotnet频道
中国IT教育
首页 ASP.NET  C#  XML/WebService ADO.NET VC.NET VB.NET .NET 资讯动态 专题 RSS订阅 讨论 下载
您现在的位置: 中国IT实验室 >> Dotnet >> C# >> 文章正文

.NET1.1开发FTP客户端

文章来源ChinaItLab 作者待缘 更新时间2006-12-12 保存本文保存本文 推荐给好友推荐给好友 收藏本页收藏本页

    前面我的一篇文章提到使用CUTEFTP的FTP引擎制作.NET的FTP上传客户端,但是这是个很郁闷的事情,首先,需要在注册表中注册这个COM,CUTEFTP的官方站提供了一段注册表写法的文章,这还好说。最关键的是,在使用这个组建的时候还需要注册产品。不会有任何人希望用户在用软件的时候却还要注册别的公司的产品先。

    前面之所以写采用CUTEFTP的引擎做客户端主要是为了方便,在一台已经安装CUTEFTP的PC上使用还是很方便的,但是我们还是希望开发独立的软件。

    实际上采用FTP进行文件传输在搞清楚FTP命令和数据连接方式后做起来也不是很难,毕竟FTP是一个公共的协议

    以下是本人写的一个简单的示例,其中的功能只有上传文件,工作模式基本说明了FTP的原理,很容易从例子中推敲出其他FTP的功能。  在近几天的BLOG文章中将陆续推出一些资料信息。

    另外,.NET2.0中在System.Net名称空间下已经封装了FTP的几个类,可以直接使用,非常方面,但是考虑到客户端对.net的兼容问题,我还是觉得采用1.1的比较好,虽然费事,但也灵活。

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Net.Sockets;
using System.IO;
 
namespace FTPUpLoad
{
     ///<summary>
     /// Main 的摘要说明。
     ///
     ///存在的问题
     ///1.中文文件名 √
     ///2.文件分批读取 √
     ///3.进度显示
     ///4.扩展到控件中
     ///</summary>
     public class MainForm : System.Windows.Forms.Form
     {
         private System.Windows.Forms.TextBox msg;
         private System.Windows.Forms.Button commBtn;
         private System.Windows.Forms.Button pathBtn;
         private System.Windows.Forms.OpenFileDialog openPath;
         private System.Windows.Forms.TextBox path;
 
         private TcpClient tcp;
         private NetworkStream ns;
         private System.Windows.Forms.Label process;
 
         ///<summary>
         ///必需的设计器变量。
         ///</summary>
         private System.ComponentModel.Container components = null;
 
         public MainForm()
         {
              //
              // Windows 窗体设计器支持所必需的
              //
              InitializeComponent();
 
              //
              // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
              //
         }
 
         ///<summary>
         ///清理所有正在使用的资源。
         ///</summary>
         protected override void Dispose( bool disposing )
         {
              if( disposing )
              {
                   if(components != null)
                   {
                       components.Dispose();
                   }
              }
              base.Dispose( disposing );
         }
        
         ///<summary>
         ///应用程序的主入口点。
         ///</summary>
         [STAThread]
         static void Main()
         {
              Application.Run(new MainForm());
         }
 
         #region Windows 窗体设计器生成的代码
         ///<summary>
         ///设计器支持所需的方法 - 不要使用代码编辑器修改
         ///此方法的内容。
         ///</summary>
         private void InitializeComponent()
         {
              this.msg = new System.Windows.Forms.TextBox();
              this.path = new System.Windows.Forms.TextBox();
              this.commBtn = new System.Windows.Forms.Button();
              this.pathBtn = new System.Windows.Forms.Button();
              this.openPath = new System.Windows.Forms.OpenFileDialog();
              this.process = new System.Windows.Forms.Label();
              this.SuspendLayout();
              //
              // msg
              //
              this.msg.Location = new System.Drawing.Point(8, 152);
              this.msg.Multiline = true;
              this.msg.Name = "msg";
              this.msg.Size = new System.Drawing.Size(552, 192);
              this.msg.TabIndex = 3;
              this.msg.Text = "";
              //
              // path
              //
              this.path.Location = new System.Drawing.Point(8, 8);
              this.path.Name = "path";
              this.path.Size = new System.Drawing.Size(440, 21);
              this.path.TabIndex = 4;
              this.path.Text = "";
              //
              // commBtn
              //
              this.commBtn.Location = new System.Drawing.Point(232, 48);
              this.commBtn.Name = "commBtn";
              this.commBtn.TabIndex = 5;
              this.commBtn.Text = "Post";
              this.commBtn.Click += new System.EventHandler(this.commBtn_Click);
              //
              // pathBtn
              //
              this.pathBtn.Location = new System.Drawing.Point(464, 8);
              this.pathBtn.Name = "pathBtn";
              this.pathBtn.TabIndex = 6;
              this.pathBtn.Text = "浏览…";
              this.pathBtn.Click += new System.EventHandler(this.pathBtn_Click);
              //
              // openPath
              //
              this.openPath.FileOk += new System.ComponentModel.CancelEventHandler(this.openPath_FileOk);
              //
              // process
              //
              this.process.Location = new System.Drawing.Point(176, 112);
              this.process.Name = "process";
              this.process.Size = new System.Drawing.Size(248, 23);
              this.process.TabIndex = 7;
              //
              // MainForm
              //
              this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
              this.ClientSize = new System.Drawing.Size(568, 358);
              this.Controls.Add(this.process);
              this.Controls.Add(this.pathBtn);
              this.Controls.Add(this.commBtn);
              this.Controls.Add(this.path);
              this.Controls.Add(this.msg);
              this.Name = "MainForm";
              this.Text = "Main";
              this.Load += new System.EventHandler(this.MainForm_Load);
              this.ResumeLayout(false);
 
         }
         #endregion
        
 

[1] [2] 下一页  

【责编:Peng】

中国IT教育

相关产品和培训
文章评论
 友情推荐链接
 认证培训
 专题推荐

 ·关于Java框架技术专题
 ·XML全攻略技术专题
 ·JAVA开源技术介绍专题
 ·Java嵌入式开发之J2ME技术专题
 ·超前体验 Oracle 11g的5个新特性
 ·揭密使用VB.NET的五个实用技巧
 ·Oracle和SQL Server常用函数对比专题
 ·展现C#世界 C#程序设计专题
 ·Java入门 Tomcat的配置技巧精华专题
 ·Oracle RMAN物理备份技术详解
 今日更新
 社区讨论
 博客论点
 频道精选
 Dotnet频道相关导航