(C# )Ftp的操作
using
using
using System.Text;
using System.Diagnostics;
using System.Text.RegularExpressions;
//从ftp上下载文件
private void Download(string filePath, string ImageSrc, string ImageName, string ftpServerIP, string
ftpUserName, string ftpPwd)
{
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
using (FileStream OutputStream = new FileStream(filePath + "\\" + ImageName, FileMode.Create))
{
FtpWebRequest ReqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" +
ImageSrc));
ReqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
ReqFTP.UseBinary = true;
ReqFTP.Credentials = new NetworkCredential(ftpUserName, ftpPwd);
using (FtpWebResponse response = (FtpWebResponse)ReqFTP.GetResponse())
{
using (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();
}
response.Close();
}
OutputStream.Close();
}
}