日期:2014-05-17  浏览次数:20916 次

C# FTP下载文件遇到错误
本帖最后由 Horane 于 2013-08-09 12:45:19 编辑
代码如下
        public void DownloadFtp(string local, string URI)
        {
            try
            {
                FtpWebRequest reqFTP;
                FileStream outputStream = new FileStream(local, FileMode.Create);
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(URI));
                reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
                reqFTP.UseBinary = true;
                reqFTP.KeepAlive = false;
                reqFTP.Credentials = new NetworkCredential("hj", "hj");
                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);