Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

How to edit file from ftp?

I fave ftp server with file aaa.txt
i want to read number from file and directly change it
is it posible and how?
0
selas
Asked:
selas
2 Solutions
 
sakuya_suCommented:
FTP does not allow files to be changed directly, if the server is linux, you can setup Shell access which will allow file changes.

otherwise you have to download the file, modify it and reupload
0
 
BlackTigerXCommented:
right, you can't change files through ftp, if you're trying to achieve that there can be many other options, depending on how much control you have over the server, if you can install a service on that server, perhaps, you could expose some functions to allow you to modify files on the server, othewise, as sakuya_su mentions, you have to download the file, modify it, and upload it
0
 
Eddie ShipmanAll-around developerCommented:
I would download it into a stream update it and then reupload it.

procedure TForm1.Button1Click(Sender: TObject);
var
  ss: TStringStream;
  sl: TStringList;
begin
  ss := TStringStream.Create('');
  sl := TStringList.Create;
  try
    IdFTP1.Connect;
    IdFTP1.ChangeDir('/public_html');
    IdFTP1.Get('test.txt', ss);
    ss.Position := 0;
    sl.Text := ss.Datastring;
    if sl.Count > 0 then
      sl[0] := 'This line changed';
  finally
    if sl.Count > 0 then
    begin
      sl.SaveToStream(ss);
      IdFTP1.Put(ss, 'test.txt');
    end;
    ss.Free;
    sl.Free;
  end;
end;
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now