用C#写的FTP服务器,在WINDOWS命令行运行正常,当用IE浏览器访问时,就提示没有访问权限源代在附件中,请高手看一下,指点指点

解决方案 »

  1.   

    class MainApp
    {
    //定义一个表FTP服务器版本的常量
    public const string Version = "0.0.1";
    //这义一个静态字符串变量,表示FTP服务器初始化的默认路径
    public static string szFtpRoot = @"E:\aspstudy";
    public static bool fDebug = false;
    public static void Usage()
    {
    Console.WriteLine("ftpd usage:");
    Console.WriteLine();
    //改变ftp目录
    Console.WriteLine("-r [path]\t:\tSpecifies FTP Root");
    //帮助
    Console.WriteLine("-?       \t:\tPrints this help");
    return;
    } public static int Main(string[] args)
    {
    for (int i = 0; i < args.Length; i++)
    {
    switch (args[i])
    {
    case "-r":
    {
    szFtpRoot = args[i + 1];
    break;
    }
    case "-?":
    {
    Usage();
    return 0;
    }
    default:
    {
    szFtpRoot = Directory.GetCurrentDirectory();
    //@"E:\aspstudy";     // Directory.GetCurrentDirectory();
    break;
    }
    }
    } //创建一个Ftpd对象实例
    Ftpd pFtpd = new Ftpd();
    //启动ftp服务
    if (pFtpd.StartServer() == false)
    { Console.WriteLine("Failed to start FTP Server.");
    return -1; } return 0;
    }
    }
      

  2.   

    public class SessionInfo
    {
    public bool fBinary = false;
    public bool fPassive = false;
    public String szFtpRoot = MainApp.szFtpRoot;
    public String szUsername;
    public PassiveInfo pi;
    } public struct PassiveInfo
    {
    //IPHostEntry类,属于System.Net名称空间,存储主机信息
    public IPHostEntry iphostentry;
    public TcpListener tcpListener;
    //32位无符号数,描述端口
    public Int32 iPort;
    }
      

  3.   

    public class Ftpd
    {
    //服务器接收一个客户请求后,产生的服务套接字
    public Socket s;
    public TcpListener TCPListener;
    //属于System.Net名称空间,用IP地址和端口号表示一个网络终端
    public IPEndPoint LocalIPEndPoint;
    public IPEndPoint localEP;
    public IPEndPoint remoteEP; public Ftpd()
    {
    //实例化一个在端口21监听的TCPListener
    TCPListener = new TcpListener(21); } //开始服务
    public bool StartServer()
    { try
    {
    //开始监听
    TCPListener.Start();
    //循环
    while (true)
    {
    //接收客户端的一个连接请求,返回一个套接字
    s = TCPListener.AcceptSocket(); /* NOTE: Would be using System.Threading.ThreadPool(s) but they are not supported on 9x systems */
    //创建一个线程,处理当前连接
    Thread client = new Thread(new ThreadStart(ServeConnection));
    //线程开始运行
    client.Start(); } }
    catch (SocketException Se)
    {
    DBG_TRACE("An Socket Class Exception Has Occured");
    DBG_TRACE("Error: {0}", Se.ErrorCode); return false;
    } } //:::
    // Function:
    // Reply()
    //
    // Purpose:
    // Sends a status command back to the client, with a descriptive message.
    //
    // Parameters:
    // Socket sSocket - Client's Connected Socket
    // int iResponseCode - Response Code to Send
    // String szMessage - Message to send
    //::: public void Reply(Socket sSocket, int iResponseCode, String szMessage)
    {
    try
    {
    String szResponse = "" + iResponseCode + " " + szMessage + "\r\n";
    //将字符串转换成ASCII码
    Byte[] OutputBytes = GetBytes(szResponse);
    //通过套接字发送
    sSocket.Send(OutputBytes);
    }
    catch (Exception)
    {
    } return; }