Download an excel(.xsl)file from server through FTP [Resolved]

Posted by Kamalakanta.Nayak09 under C# on 5/15/2012 | Points: 10 | Views : 7780 | Status : [Member] | Replies : 1
What is the code(ASP.Net) for down loading the .xsl file from sever thrugh ftp?

Thanks,
K.K



Responses

Posted by: Jpchoudhari on: 5/15/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi,

This code should do your work.

FtpWebRequest reqFTP;

try
{
//filePath = <<The full path where the file is to be created.>>,
//fileName = <<Name of the file to be created(Need not be the name of the file on FTP server).>>
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)
{
MessageBox.Show(ex.Message);
}


Kind Regards,
Jay

Kamalakanta.Nayak09, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response