昊漫玉 发表于 2015-5-26 10:44:21

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());
      }
    }
}
页: [1]
查看完整版本: C# ftp服务