日期:2014-05-17 浏览次数:20944 次
string ftpServerIP = "192.9.123.123";
string ftpUserID = "user";
string ftpPassword = "pwd";
string fileName = "new.fr3";
string filePath = @"d:\new";
public bool getftpfile(string ftpServerIP, string ftpUserID, string ftpPassword, string filePath, string fileName)
{
if (checkftpfile(ftpServerIP, ftpUserID, ftpPassword, filePath, fileName) == false)
{
return false;
}
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
FileStream outputStream = new FileStream(filePath +@"\" + fileName,FileMode.Create);
try
{
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/IC" + fileName));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
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,&n