日期:2014-05-17 浏览次数:20916 次
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);