Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to resume or pause the FTPWebRequest in C#.NET

How to resume or pause the FTPWebRequest in C#.NET

Scheduled Pinned Locked Moved C#
csharpsysadminhelptutorialcareer
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kumaran21cen
    wrote on last edited by
    #1

    Hi All, Iam using FTPWebRequest for downloading the files... Here, the function is working good. but while downloading the file, if the internet connection goes down, then this program going to throws the exception and end the process. So, in this scenario i want to pause/resume downloading... How to acheive this... If anybody knows help me... thanks Here my sample code ------------------- public void Download(string fileName) { //Desc: To download the file from the ftp server FtpWebRequest reqFTP; try { //fileName = <<Name of the file to be createdNeed not name on FTP server. name name()>> FileStream outputStream = new FileStream(downloadPath + "\\" + fileName, FileMode.Create); reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + ftpPath + "/" + 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); } reqFTP.Abort(); ftpStream.Close(); outputStream.Close(); response.Close(); } catch (Exception ex) { Utils.Write(ex.Message); } }

    Thanks & Regards Kumaran

    D 1 Reply Last reply
    0
    • K Kumaran21cen

      Hi All, Iam using FTPWebRequest for downloading the files... Here, the function is working good. but while downloading the file, if the internet connection goes down, then this program going to throws the exception and end the process. So, in this scenario i want to pause/resume downloading... How to acheive this... If anybody knows help me... thanks Here my sample code ------------------- public void Download(string fileName) { //Desc: To download the file from the ftp server FtpWebRequest reqFTP; try { //fileName = <<Name of the file to be createdNeed not name on FTP server. name name()>> FileStream outputStream = new FileStream(downloadPath + "\\" + fileName, FileMode.Create); reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + ftpPath + "/" + 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); } reqFTP.Abort(); ftpStream.Close(); outputStream.Close(); response.Close(); } catch (Exception ex) { Utils.Write(ex.Message); } }

      Thanks & Regards Kumaran

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You can't pause and resume the download, but you can start a new download and start it from a certain point. Have a look at the ContentOffset property of the FtpWebRequest object. Also you can find examples of this just by Googling for "ftpwebrequest resume download".

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups