views:

53

answers:

1

Hi,

I have a requirement to edit a remote text file on-the-fly, the content of which currently stands at ~1Mb.

I have tried a couple of approaches and both seem to be clunky or hog memory which I can't rely on.

Thinking out logically what I'm trying to achieve is:

  1. FTP to a remote server.
  2. Download a copy of the file for backup purposes and store it somewhere locally.
  3. Open the remote file and add the necessary lines required.
  4. Remove lines from the remote file as per an array of un-required data generated from the local server.

Is this possible?

I've managed to code steps 1 and 2 but I'm having difficult with 3 and 4. The way I'm doing it now is to use fgets and return the whole string. Really, I don't want to do this as it involves manipulating and re-generating the whole string (and it's large) and then re-inserting it in between two markers in the remote file.

Is there no way of manipulating the lines of text in the file on-the-fly?

+1  A: 

To the best of my knowledge you cannot do 3 and 4 via FTP. It does not allow manipulation of remote files, its for file transferring only.

zaf
Are there any methods for achieving this? I could download the file and then perform the manipulating on our server and then re-upload.
Of course, you retrieve the file, update it and then transfer it back.
zaf
But this still leaves me with the issue of manipulating the file directly rather than reading the content, editing and re-inserting.
Sorry, can you elaborate more?
zaf