una versione per kylix e fp che fa quello che chiedi e utilizza la potente libreria libc
Codice PHP:
procedure TTBase.TrasferisciPagina ;
const
LF = ^J;
READ_IOMode = 'r';
var
nome_file : string;
locale_adr, remote_adr : string;
transf_dati : string;
str, host, user, psw : string;
CmdArr : array[0..512] of char;
StrArr : array[0..512] of char;
F : PIOFILE;
pPipeStr : Pointer;
s : string;
pid, pid_child : integer;
dir_base : string;
begin
// lo preleva dalle impostazioni
locale_adr := SetLocaleAdrMacro(IniFile.ReadString('Indirizzi Fisici', 'Root', '/var/www/html'));
with DominiTbl do
begin
remote_adr := FieldByName('adr_root');
remote_adr := SetRemoteAdrMacro(fDominio, remote_adr);
transf_dati := FieldByName('transf_dati');
host := FieldByName('ftp_host');
user := FieldByName('ftp_user');
psw := FieldByName('ftp_password');
end;
nome_file := GetFileName;
// crea uno script per il trasferimento dei dati
dir_base := ExtractFileDir(Application.ExeName);
// crea la directory bin se non esiste
CreateDir(dir_base + '/bin');
// if not FileExists(dir_base + '/bin/trasf_pagina') then
begin
with TStringList.Create do
begin
Add('#!/bin/bash');
Add('#creato da ' + automaticamente' + ' il ' + DateToStr(Now));
// trasferisce via ssh o via rtp
if transf_dati = 'ssh' then
begin
Add('scp $1/$3 ' + user + '@' +host + ':$2');
end
else
begin
Add('ftp ' + host + ' << EOF');
Add(' lcd $1');
Add(' cd $2');
Add(' put $3');
Add('EOF');
end;
SaveToFile(dir_base + '/bin/trasf_pagina');
Free;
end;
// dà i permessi di esecuzione al nuovo file
str := dir_base + '/bin/trasf_pagina' + #0;
chmod(@str[1], S_IRUSR Or S_IWUSR Or S_IXUSR);
end;
str := dir_base + '/bin/trasf_pagina ' + locale_adr + ' ' + remote_adr + ' ' + nome_file + #0;
pid := fork;
case pid of
0 : begin
pid_child := GetPid;
StrCopy(cmdArr, @str[1]);
F := popen(CmdArr, READ_IOMode);
if assigned(F) then
begin
repeat
pPipeStr := fgets(StrArr, 1024, F);
if Assigned(pPipeStr) then
begin
LogFile.Write(StrPas(pPipeStr));
end;
until not Assigned(pPipeStr);
pClose(F);
end;
kill(pid_child, SIGTERM);
end;
end;
end;
ciao
sergio