如题.....
程序一开始连接一次服务器!
考虑到网络时断时续.
在程序中如何知道FTP服务器是否已经连接或是断开!

解决方案 »

  1.   

    高手帮帮忙~~如果能跟踪到FTP服务器的断开事件也好!!!
      

  2.   

    网上找的一个类连接方法如下
    public void Connect()
    {
    socketControl = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
    IPEndPoint ep = new IPEndPoint(IPAddress.Parse(RemoteHost), strRemotePort);
    // 链接
    try
    {
    socketControl.Connect(ep);
    }
    catch(Exception)
    {
                throw new IOException("Couldn't connect to remote server");
    }   // 获取应答码
    ReadReply();
    if(iReplyCode != 220)
    {
    DisConnect();
    throw new IOException(strReply.Substring(4));
    }   // 登陆
    SendCommand("USER "+strRemoteUser);
    if( !(iReplyCode == 331 || iReplyCode == 230) )
    {
    CloseSocketConnect();//关闭连接
    throw new IOException(strReply.Substring(4));
    }
    if( iReplyCode != 230 )
    {
    SendCommand("PASS "+strRemotePass);
    if( !(iReplyCode == 230 || iReplyCode == 202) )
    {
    CloseSocketConnect();//关闭连接
    throw new IOException(strReply.Substring(4));
    }
    }
    bConnected = true;   // 切换到目录
    ChDir(strRemotePath);
    }