• 大小: 6.41MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-08-12
  • 语言: C#
  • 标签: C#  FTP  

资源简介

采用FTP PASV模式设计一个FTP服务器程序和一个FTP客户机程序,具有文件夹内容浏览和文件下载功能,服务器程序能够接受多个客户机的FTP请求并且能够对客户机身份进行验证。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;

using System.Collections;
using System.Net.NetworkInformation;


namespace client
{
   

    public partial class Form1 : Form
    {
        TcpClient controltc;
        NetworkStream controlns;
        StreamReader controlsr;
        StreamWriter controlsw;



        private static string ext =null;


        public Form1()
        {
            InitializeComponent();
            this.buttonUpDir.Enabled= false;

            Control.CheckForIllegalCrossThreadCalls = false;
        }

        
        private void closecontrolconnection()
        {
            this.controltc.Close();
            this.controlns.Close();
            this.controlsr.Close();
            this.controlsw.Close();
        }
        private void buttonConnect_Click(object sender EventArgs e)
        {
            try
            {
            
                controltc = new TcpClient(“127.0.0.1“ 21);
            }
            catch (Exception ee)
            {
                MessageBox.Show(“与服务器连接失败!“ + ee.ToString());
                return;
            }
            controlns = controltc.GetStream();
            controlsr = new StreamReader(controlns System.Text.Encoding.Unicode);
            controlsw = new StreamWriter(controlns System.Text.Encoding.Unicode);

            string str = controlsr.ReadLine();
            this.listBoxInfo.Items.Add(“收到:“ + str);

            controlsw.WriteLine(“USER ftpuser“);
            controlsw.Flush();
            str = controlsr.ReadLine();


            this.listBoxInfo.Items.Add(“收到“+str);
            if (str == “421“)
            {
                MessageBox.Show(“用户名不正确“);
                this.closecontrolconnection();
                return;
            }

            controlsw.WriteLine(“PASS ftppass“);
            controlsw.Flush();
            str = controlsr.ReadLine();
            this.listBoxInfo.Items.Add(“收到:“ + str);
            if (str == “421“)
            {
                MessageBox.Show(“密码不正确“);
                this.closecontrolconnection();
                return;
            }

          //获取FTP根目录下的子目录和文件列表
            GetDirAndFiles(@“server:\“);
        }
        private void button1_Click(object sender EventArgs e)
        {
           
        }
        private void GetDirAndFiles(string path)
        {
            this.groupBoxDir.Text = path;
            //-------判断当前目录是否为虚拟根目录---------
            if (path == @“server:\“)
            {
                this.buttonUpDir.Enabled = false;
            }
            else
            {
                this.buttonUpDir.Enabled = true;
           

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-12-02 14:04  client\
     目录           0  2018-12-02 14:04  client\.vs\
     目录           0  2018-12-02 14:16  client\.vs\client\
     目录           0  2018-12-02 14:04  client\.vs\client\v14\
     文件       44544  2018-11-27 23:13  client\.vs\client\v14\.suo
     目录           0  2018-12-02 14:18  client\.vs\client\v15\
     文件       47104  2018-12-02 14:51  client\.vs\client\v15\.suo
     目录           0  2018-12-02 14:18  client\.vs\client\v15\Server\
     目录           0  2018-12-02 14:18  client\.vs\client\v15\Server\sqlite3\
     文件           0  2018-12-02 14:18  client\.vs\client\v15\Server\sqlite3\db.lock
     文件        4096  2018-12-02 14:18  client\.vs\client\v15\Server\sqlite3\storage.ide
     文件       32768  2018-12-02 14:18  client\.vs\client\v15\Server\sqlite3\storage.ide-shm
     文件      782832  2018-12-02 14:20  client\.vs\client\v15\Server\sqlite3\storage.ide-wal
     文件       17408  2018-11-27 23:13  client\client.exe
     文件         985  2018-11-27 23:13  client\client.sln
     目录           0  2018-12-02 14:20  client\client\
     文件         189  2018-11-27 23:13  client\client\App.config
     目录           0  2018-12-02 14:04  client\client\bin\
     目录           0  2018-12-02 14:04  client\client\bin\Debug\
     文件       17920  2018-12-02 14:22  client\client\bin\Debug\client.exe
     文件         189  2018-11-27 23:13  client\client\bin\Debug\client.exe.config
     文件       34304  2018-12-02 14:22  client\client\bin\Debug\client.pdb
     文件       11592  2018-11-28 07:51  client\client\bin\Debug\client.vshost.exe
     文件         189  2018-11-27 23:13  client\client\bin\Debug\client.vshost.exe.config
     文件         490  2014-01-13 21:31  client\client\bin\Debug\client.vshost.exe.manifest
     文件     5641456  2018-11-27 23:13  client\client\bin\Debug\mscorlib.dll
     文件       59342  2018-11-27 23:13  client\client\bin\Debug\normidna.nlp
     文件       47076  2018-11-27 23:13  client\client\bin\Debug\normnfc.nlp
     文件       40566  2018-11-27 23:13  client\client\bin\Debug\normnfd.nlp
     文件       67808  2018-11-27 23:13  client\client\bin\Debug\normnfkc.nlp
     文件       61718  2018-11-27 23:13  client\client\bin\Debug\normnfkd.nlp
............此处省略94个文件信息

评论

共有 条评论