ftp://dy:[email protected]:10071/[迅雷下载www.2tu.cc]爱谁谁.DVDsrc国语中字.rmvb
想这种c#怎么读取,有人写过吗?

解决方案 »

  1.   

    ftp协议的文件,没办法直接读取,必须先下载,然后再在本地读取。可以使用ftpwebrequest类。
      

  2.   


     FtpWebRequest reqFTP;            try
                {
                    FileStream outputStream = new FileStream("D:" + "\\" + "kaishi", FileMode.Create);                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + "xlj.2tu.cc:10071" + "/" + "[迅雷下载www.2tu.cc]爱谁谁.DVDsrc国语中字.rmvb"));                reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;                reqFTP.UseBinary = true;                reqFTP.Credentials = new NetworkCredential("dy", "dy");                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();                Stream ftpStream = response.GetResponseStream();                long cl = response.ContentLength;                int bufferSize = 2048;                int readCount;                byte[] buffer = new byte[bufferSize];                readCount = ftpStream.Read(buffer, 0, bufferSize);                while (readCount > 0)
                    {
                        outputStream.Write(buffer, 0, readCount);                    readCount = ftpStream.Read(buffer, 0, bufferSize);
                    }                ftpStream.Close();                outputStream.Close();                response.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }这么写可以吗?