资源简介

完整代码,重新编译,界面非常人性化,而且注释很清晰。能够实现登陆、匿名登陆、上传、下载、创建、删除等功能,对初学者有很好的参考价值。

资源截图

代码片段和文件信息

using System;
using System.IO;
// 添加命令空间
using System.Net;
using System.Text;
using System.Windows.Forms;

namespace FTP
{
    public partial class Form1 : Form
    {
        private const int ftpport = 21;
        private string ftpUristring = null;
        private NetworkCredential networkCredential;
        private string currentDir = “/“;
        public Form1()
        {
            InitializeComponent();
            IPAddress[] ips = Dns.GetHostAddresses(““);
            ServerIp.Text = ips[1].ToString();
            ServerIp.SelectAll();
            logout.Enabled = false;
            FtpResources.Enabled = false;
            FtpState.Enabled = false;
            Upload.Enabled = false;
            download.Enabled = false;
            Delete.Enabled = false;
        }

        #region 键盘按下事件

        private void tbxServerIp_KeyPress(object sender KeyPressEventArgs e)
        {
            // 输入用户名回车后,焦点直接转到密码文本框
            if (e.KeyChar == (char)13)
            {
                Username.Focus();
            }
        }

        private void tbxUsername_KeyPress(object sender KeyPressEventArgs e)
        {
            // 输入用户名回车后,焦点直接转到密码文本框
            if (e.KeyChar == (char)13)
            {
                Password.Focus();
            }
        }

        private void tbxPassword_KeyPress(object sender KeyPressEventArgs e)
        {
            // 输入密码回车后直接可以登录
            if (e.KeyChar == (char)13)
            {
                login.Focus();
            }
        }
        #endregion

        // 匿名复选框Click事件
        private void Anonymous_Click(object sender EventArgs e)
        {
            // 实名方式登录
            // 此时需要输入用户名和密码
            if (Anonymous.Checked == false)
            {
                Username.Enabled = true;
                Username.Text = “user1“;
                Password.Enabled = true;
                Password.Text = ““;
                Username.Focus();
            }
            // 匿名方式
            else
            {
                Username.Text = “anonymous“;
                Username.Enabled = false;
                Password.Text = ““;
                Password.Enabled = false;
            }
        }


        #region 与服务器的交互
        
        // 创建FTP连接
        private FtpWebRequest CreateFtpWebRequest(string uri string requestMethod)
        {
            FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(uri);
            request.Credentials = networkCredential;
            request.KeepAlive = true;
            request.UseBinary = true;
            request.Method = requestMethod;
            return request;
        }

        // 获取服务器返回的响应体
        private FtpWebResponse GetFtpResponse(FtpWebRequest request)
        {
            FtpWebResponse response = null;
            try
            {
                response = (FtpWebResponse)request.GetResponse();
                FtpState.Items.Add(

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     47616  2016-04-07 15:26  FTP\.vs\FTP\v14\.suo

     文件      20480  2015-06-10 15:56  FTP\FTP\bin\Debug\FTP.exe

     文件      36352  2015-06-10 15:56  FTP\FTP\bin\Debug\FTP.pdb

     文件      23168  2015-06-10 20:37  FTP\FTP\bin\Debug\FTP.vshost.exe

     文件        490  2013-06-18 20:28  FTP\FTP\bin\Debug\FTP.vshost.exe.manifest

     文件      19968  2015-06-10 15:21  FTP\FTP\bin\Debug\FTPUpDownloader.exe

     文件      42496  2015-06-10 15:21  FTP\FTP\bin\Debug\FTPUpDownloader.pdb

     文件        490  2013-06-18 20:28  FTP\FTP\bin\Debug\FTPUpDownloader.vshost.exe.manifest

     文件      22528  2016-04-07 10:22  FTP\FTP\bin\Release\FTP.exe

     文件      30208  2016-04-07 10:22  FTP\FTP\bin\Release\FTP.pdb

     文件      22696  2016-04-07 15:26  FTP\FTP\bin\Release\FTP.vshost.exe

     文件        490  2015-10-30 15:19  FTP\FTP\bin\Release\FTP.vshost.exe.manifest

     文件      20078  2015-06-13 12:45  FTP\FTP\Form1.cs

     文件      12088  2015-06-13 12:45  FTP\FTP\Form1.Designer.cs

     文件      11015  2015-06-13 09:57  FTP\FTP\Form1.resx

     文件       5345  2015-06-10 15:32  FTP\FTP\FTP.csproj

     文件        478  2015-06-10 15:32  FTP\FTP\FTP.csproj.user

     文件       3262  2015-06-13 09:55  FTP\FTP\FTP.ico

     文件       5426  2015-06-10 15:55  FTP\FTP\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6948  2015-06-10 15:33  FTP\FTP\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        398  2015-06-10 20:37  FTP\FTP\obj\x86\Debug\FTP.csproj.FileListAbsolute.txt

     文件        977  2015-06-10 15:52  FTP\FTP\obj\x86\Debug\FTP.csproj.GenerateResource.Cache

     文件       9180  2015-06-10 15:33  FTP\FTP\obj\x86\Debug\FTP.csprojResolveAssemblyReference.cache

     文件      20480  2015-06-10 15:56  FTP\FTP\obj\x86\Debug\FTP.exe

     文件      36352  2015-06-10 15:56  FTP\FTP\obj\x86\Debug\FTP.pdb

     文件        180  2015-06-10 15:33  FTP\FTP\obj\x86\Debug\FTP.Properties.Resources.resources

     文件       1627  2015-06-10 15:25  FTP\FTP\obj\x86\Debug\FTPUpDownloader.csproj.FileListAbsolute.txt

     文件        904  2015-06-10 15:21  FTP\FTP\obj\x86\Debug\FTPUpDownloader.csproj.GenerateResource.Cache

     文件       9180  2015-06-10 15:21  FTP\FTP\obj\x86\Debug\FTPUpDownloader.csprojResolveAssemblyReference.cache

     文件      19968  2015-06-10 15:21  FTP\FTP\obj\x86\Debug\FTPUpDownloader.exe

............此处省略41个文件信息

评论

共有 条评论