I am trying to download files from FTP. The requirement is to show a progress bar with Downloadingsize/Filesize and percentage.
I am able to display progress bar on Windows Form Application but On web application hosted on Local IIS server, I am getting a problem. I am using below code to download files from FTP on generic handler
- public bool DownLoadFilesFromFTp(string fileName,string ftpFolder)
- {
-
- try
- {
- string Ftp_Host = System.Configuration.ConfigurationManager.AppSettings["Ftp_Host"];
- string Ftp_UserName = System.Configuration.ConfigurationManager.AppSettings["Ftp_UserName"];
- string Password = System.Configuration.ConfigurationManager.AppSettings["Password"];
- string downloadpath= System.Configuration.ConfigurationManager.AppSettings["downloadpath"];
-
- string ftpurl = Ftp_Host + ftpFolder + "/" + fileName;
- FtpWebRequest reqFTP;
- reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpurl));
- reqFTP.Credentials = new NetworkCredential(Ftp_UserName, Password);
- reqFTP.KeepAlive = false;
- reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
- reqFTP.UseBinary = true;
- reqFTP.Proxy = null;
- reqFTP.UsePassive = false;
-
- FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
- Stream responseStream = response.GetResponseStream();
- FileStream writeStream = null;
-
- writeStream = new FileStream(downloadpath + fileName, FileMode.Create); int Length = 2048;
-
- Byte[] buffer = new Byte[Length];
- int bytesRead = responseStream.Read(buffer, 0, Length);
- while (bytesRead > 0)
- {
- writeStream.Write(buffer, 0, bytesRead);
- bytesRead = responseStream.Read(buffer, 0, Length);
- }
-
-
- responseStream.Close();
- writeStream.Close();
- response.Close();
- return true;
- }
- catch (WebException wEx)
- {
- return false;
-
- }
- catch (Exception ex)
- {
- return false;
-
- }
- }
- public void ProcessRequest(HttpContext context)
- {
- DownLoadFilesFromFTp("FileName.pdf", "Foldername");
-
- }
class="progress CustomProgress">
-
"FileProgress"
class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;"> -
-
> $("#MainContent_btnDownload").click(function () { $.ajax({ type: "POST", url: "Downloader.ashx", success: function (data) { } }); }); I want to add below progress listener on my above ajax call
- function progressHandlingFunction(e) {
- var TotalFileSize = GetFileSize( e.total);
- if (e.lengthComputable) {
-
-
- $("#FileProgress").show();
- var percentComplete = Math.round(e.loaded * 100 / e.total);
-
- $("#FileProgress").css("width", percentComplete + '%').attr('aria-valuenow', percentComplete);
- $('#FileProgress span').text(percentComplete + "%");
-
- $("#progressreport").html("Uploading " + GetFileSize(e.loaded) + " of " + TotalFileSize);
-
- }
- else {
- $('#FileProgress span').text('unable to compute');
- }
- }
How can call this function on ajax request