Editing a file over FTP
-
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 -
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 greatPerhaps 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; }
-
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 greatHello, 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