hi guys ;
I listed the ftp files on gridview Asp.net and also I wanna download listed ftp files , How Can I do .
I have 4 columns in gridview , Filename, File Size , Created Date , Download , When I click the download button wanna the start download process .
Thank in advance .
Demir AcarPosted Jun 7, 2015, 3:47 PM
Manoj BhoirPosted Jun 7, 2015, 10:47 AM
{
FtpWebRequest reqFTP;
try
{
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" +
ftpServerIP + "/" + 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, 0, bufferSize);
ftpStream.Close();
response.Close();
this.Response.ClearContent();
this.Response.Clear();
this.Response.ContentType = "APPLICATION/OCTET-STREAM";
String Header = "Attachment; Filename=" + fileName;
this.Response.AppendHeader("Content-Disposition", Header);
this.Response.BinaryWrite(buffer);
}
catch (Exception ex)
{
}
this.Response.End(); // This line is very important
}
Demir AcarPosted Jun 7, 2015, 8:35 AM
Manoj BhoirPosted Jun 6, 2015, 11:58 PM
{
FtpWebRequest reqFTP;
try
{
//filePath = <
//fileName = <
FileStream outputStream = new FileStream(filePath +
"\\" + fileName, FileMode.Create);
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" +
ftpServerIP + "/" + 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, 0, bufferSize);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
ftpStream.Close();
outputStream.Close();
response.Close();
}
catch (Exception ex)
{
}
}