C# ftp服务

/********************************************************************
 created: 2008/04/16
 created: 16:4:2008   11:07
 filename:  F:\Workspace\Midapex\Src\Net\OurFtpServer\Program.cs
 file path: F:\Workspace\Midapex\Src\Net\OurFtpServer
 file base: Program
 file ext: cs
 author:  Deng.Yangjun@Gmail.com
 
 purpose: 
*********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using Midapex.Net.Ftp;
using Midapex.Net;

namespace OurFtpServer
{
    class Program
    {
        static void Main(string[] args)
        {
            Trace.Listeners.Add(new ConsoleTraceListener());

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            try
            {
                Console.WriteLine("********************************************************************");
                Console.WriteLine("Midapex Village FTP Server V2.1");
                Console.WriteLine("(C)2006-2008 Midapex Village");
                Console.WriteLine("********************************************************************");
                Console.WriteLine("");

                using (FtpServer server = new FtpServer())
                {
                    Console.WriteLine("测试帐号:anonymous(匿名登陆,具有读权限), ftp(密码:ftp,具有读写权限)");

                    /*
                     * 服务器的最大连接数
                     */
                    server.Capacity = 1000;

                    /*
                     * 连接超时时间
                     */
                    server.HeartBeatPeriod = 120000;  //120秒

                    /*
                     * 创建一个使用FTP的用户,
                     */
                    FtpUser user = new FtpUser("ftp");
                    user.Password = "ftp";
                    user.AllowWrite = true;
                    user.HomeDir = Environment.CurrentDirectory;

                    /*
                     * 限制该帐号的用户的连接服务器的最大连接数
                     * 也就是限制该使用该帐号的FTP同时连接服务器的数量。
                     */
                    user.MaxConnectionCount = 2;

                    /*
                     * 限制用户的最大上传文件为20M,超过这个值上传文件会失败。
                     * 默认不限制该值,可以传输大文件。
                     */
                    user.MaxUploadFileLength = 1024 * 1024 * 20;
                    server.AddUser(user);

                    //把当前目录作为匿名用户的目录,测试目的(必须指定)
                    server.AnonymousUser.HomeDir = Environment.CurrentDirectory;

                    server.Start();
                    Console.WriteLine("Press enter to exit...");
                    Console.ReadLine();
                    server.Stop();
                }
            }
            catch (System.Exception e)
            {
                NetDebuger.PrintErrorMessage("FATAL ERROR:" + e.Message);
            }

        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            NetDebuger.PrintErrorMessage("UNHANDLED ERROR:" + e.ExceptionObject.ToString());
        }
    }
}

转载于:https://www.cnblogs.com/gengxiaochao/archive/2008/05/11/1191818.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值