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. Editing a file over FTP

Editing a file over FTP

Scheduled Pinned Locked Moved C#
helpquestion
3 Posts 3 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.
  • A Offline
    A Offline
    Anthony Mushrow
    wrote on last edited by
    #1

    Well with how well HttpWebRequest worked reading a file, i though FTP would be just a s easy, not quite so, i have: FtpWebRequest request =(FtpWebRequest)WebRequest.Create(@"ftp://address/1.txt"); request.Credentials = new NetworkCredential("username", "password"); request.Method = WebRequestMethods.Ftp.AppendFile; Stream FS = request.GetRequestStream(); StreamReader SR = new StreamReader(FS, true); string line = SR.ReadLine(); I imagined that that would read the file, i was wrong, says that the stream is not readable. So apart from the not being able to read the file, i need to be able to edit the file, and there would be the possibility of multiple people trying to edit it at the same time, how would i do this? (No two people would be editing the same line in the file, if that makes any difference at all) So err, any help or suggestions would be great

    G D 2 Replies Last reply
    0
    • A Anthony Mushrow

      Well with how well HttpWebRequest worked reading a file, i though FTP would be just a s easy, not quite so, i have: FtpWebRequest request =(FtpWebRequest)WebRequest.Create(@"ftp://address/1.txt"); request.Credentials = new NetworkCredential("username", "password"); request.Method = WebRequestMethods.Ftp.AppendFile; Stream FS = request.GetRequestStream(); StreamReader SR = new StreamReader(FS, true); string line = SR.ReadLine(); I imagined that that would read the file, i was wrong, says that the stream is not readable. So apart from the not being able to read the file, i need to be able to edit the file, and there would be the possibility of multiple people trying to edit it at the same time, how would i do this? (No two people would be editing the same line in the file, if that makes any difference at all) So err, any help or suggestions would be great

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Perhaps if you try the Download protocol instead of the AppendFile protocol. The AppendFile protocol is used to append a file to another on the FTP server. You can't edit a file over FTP. You have to first download the file, edit it, and then upload it. If multiple people should be able to edit the file, you would have to download the latest version of the file to match it with the edited version before you can upload it. Also you should use some way to lock the file while you are matching it, so that two people can't do a match at the same time, perhaps rename the file while you are working with it.

      --- b { font-weight: normal; }

      1 Reply Last reply
      0
      • A Anthony Mushrow

        Well with how well HttpWebRequest worked reading a file, i though FTP would be just a s easy, not quite so, i have: FtpWebRequest request =(FtpWebRequest)WebRequest.Create(@"ftp://address/1.txt"); request.Credentials = new NetworkCredential("username", "password"); request.Method = WebRequestMethods.Ftp.AppendFile; Stream FS = request.GetRequestStream(); StreamReader SR = new StreamReader(FS, true); string line = SR.ReadLine(); I imagined that that would read the file, i was wrong, says that the stream is not readable. So apart from the not being able to read the file, i need to be able to edit the file, and there would be the possibility of multiple people trying to edit it at the same time, how would i do this? (No two people would be editing the same line in the file, if that makes any difference at all) So err, any help or suggestions would be great

        D Offline
        D Offline
        Daniel Monzert
        wrote on last edited by
        #3

        Hello, I am not 100% sure about that, but the methods seem similar to the HttpRequest. The "request stream" is not readable, because you make your request to the server through it, it is a writable stream. There is another stream, the "response stream" which is sent to you after you call GetResponseStream() at some class (guess it was the request, too). Get request stream, write data into if you need, get response stream, read it. Regards, d.mon

        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