본문으로 바로가기

ASP.NET FTP DOWNLOAD 간단 모듈

category .NET/ASP.NET 2013. 11. 27. 14:19
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(FilePath);
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential('FTP아이디','FTP암호');
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)
{
	Response.AddHeader("Content-Disposition", "attachment;filename=파일 이름");
	Response.ContentType = "application/unknown";
	Response.OutputStream.Write(buffer, 0, readCount);
	readCount = ftpStream.Read(buffer, 0, bufferSize);
}
웹에서 다운로드 받거나 모바일(웹뷰포함)에서 다운로드 할때 유용할듯..