• 大小: 64KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-24
  • 语言: C#
  • 标签: C#  FTP服务器  源码  

资源简介

vs2005编写通用FTP服务器程序的源码,标准ftp协议,没有客户端程序,可以直接用dos下的ftp命令进行连接,dos下的ftp命令默认端口为21。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
using System.Threading;

namespace FtpSever
{
    public class Client
    {
        int dataPort = 5380;
        internal FtpServerForm server;
        private Request request;

        //当前连接的状态
        internal bool isLogin = false;
        //工作目录
        internal string workingDir;

        private delegate void removeHandler(Client c);

        private string user;
        public string User
        {
            get { return user; }
            set { user = value; }
        }

        private string password;
        public string Password
        {
            get { return password; }
            set { password = value; }
        }

        private Socket currentSocket = null;
        public Socket CurrentSocket
        {
            get { return currentSocket; }
            set { currentSocket = value; }
        }

        private string ipAdd;
        public string IpAddress
        {
            get { return ipAdd; }
            set { ipAdd = value; }
        }

        private int port;
        public int Port
        {
            get { return port; }
            set { port = value; }
        }

        private bool stopFlag;
        public bool StopFlag
        {
            get { return stopFlag; }
            set { stopFlag = value; }
        }

        private string fileName;
        public string FileName
        {
            get { return fileName; }
            set { fileName = value; }
        }

        private string currentCmd;
        public string CurrentCmd
        {
            get { return currentCmd; }
            set { currentCmd = value; }
        }

        public Client(FtpServerForm sf Socket so)
        {
            this.server = sf;
            this.currentSocket = so;
            ipAdd = ((IPEndPoint)currentSocket.RemoteEndPoint).ToString();
            port = server.port;
            workingDir = FtpServerForm.ROOT_DIR;
            request = new Request(this);
            
        }

        public void ServiceClient()
        {
            stopFlag = false;
            isLogin = false;
            sendMsg(“220 欢迎使用FTP服务器,你已经连上了服务器...“);
            try
            {
                if (request.parseCmd(receiveCmd()) != Request.LOGIN_USER)
                {
                    sendMsg(“221 命令错误“);
                    currentSocket.Close();
                    server.Invoke(new removeHandler(server.removeClient) new Client[] { this });
                    return;
                }
                sendMsg(“331 请输入用户“ + user + “的登录密码“);
                if (request.parseCmd(receiveCmd()) != Request.LOGIN_PASS)
                {
                    sendMsg(“221 命令错误“);
                    currentSocket.Close();
                    server.Invoke(new removeHandler(serve

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

     文件       5612  2009-07-11 16:42  FtpSever\Properties\Resources.resx

     文件        249  2009-07-11 16:42  FtpSever\Properties\Settings.settings

     文件       1188  2009-07-11 16:42  FtpSever\Properties\AssemblyInfo.cs

     文件       2870  2009-07-11 16:42  FtpSever\Properties\Resources.Designer.cs

     文件       1091  2009-07-11 16:42  FtpSever\Properties\Settings.Designer.cs

     文件       5804  2009-07-12 16:28  FtpSever\FtpServerForm.cs

     文件       6246  2009-07-12 16:28  FtpSever\FtpServerForm.Designer.cs

     文件       3338  2009-07-11 18:58  FtpSever\FtpSever.csproj

     文件       5632  2005-11-11 22:25  FtpSever\bin\Debug\FtpSever.vshost.exe

     文件      36864  2009-07-12 16:28  FtpSever\bin\Debug\FtpSever.exe

     文件      52736  2009-07-12 16:28  FtpSever\bin\Debug\FtpSever.pdb

     文件        180  2009-07-11 16:59  FtpSever\obj\Debug\FtpSever.Properties.Resources.resources

     文件      36864  2009-07-12 16:28  FtpSever\obj\Debug\FtpSever.exe

     文件        180  2009-07-12 16:28  FtpSever\obj\Debug\FtpSever.FtpServerForm.resources

     文件      52736  2009-07-12 16:28  FtpSever\obj\Debug\FtpSever.pdb

     文件        908  2009-07-12 16:28  FtpSever\obj\Debug\FtpSever.csproj.GenerateResource.Cache

     文件        283  2009-07-12 16:29  FtpSever\obj\FtpSever.csproj.FileList.txt

     文件       8299  2009-07-12 16:19  FtpSever\Client.cs

     文件      15961  2009-07-12 16:14  FtpSever\Request.cs

     文件       5814  2009-07-12 16:28  FtpSever\FtpServerForm.resx

     文件        904  2009-07-11 16:42  FtpSever\FtpSever.sln

    ..A..H.     15360  2009-07-12 16:29  FtpSever\FtpSever.suo

     文件        475  2009-07-11 17:24  FtpSever\Program.cs

     目录          0  2009-07-11 16:42  FtpSever\obj\Debug\TempPE

     目录          0  2009-07-11 17:02  FtpSever\obj\Debug\Refactor

     目录          0  2009-07-11 16:42  FtpSever\bin\Debug

     目录          0  2009-07-11 16:42  FtpSever\obj\Debug

     目录          0  2009-07-11 16:42  FtpSever\Properties

     目录          0  2009-07-11 16:42  FtpSever\bin

     目录          0  2009-07-11 16:42  FtpSever\obj

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

评论

共有 条评论