|
{
|
|
Aulalinex 3.0-7 Software de gestión de Aulas Tecnológicas
|
|
Copyright (C) 2008-2009, Consejería de Educación,Junta de Extremadura
|
|
Programación: Manuel Narváez Martínez <mnarvaez007@gmail.com>
|
|
Diseño gráfico: Ana María Zamora Moreno
|
|
Desarrollado con Lazarus 0.9.26
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
}
|
|
unit clrecibir;
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
interface
|
|
|
|
uses
|
|
globales,Classes, SysUtils, unix, IdTCPClient;
|
|
type
|
|
ThrRecibir = class(TThread)
|
|
private
|
|
{ Private declarations }
|
|
fusuario,fmicarpeta,fhost,fcomando:string;
|
|
fcliente:TIdTcpClient;
|
|
fPuerto:integer;
|
|
protected
|
|
procedure Execute; override;
|
|
public
|
|
constructor Create(usuario,host,comando,micarpeta:string);
|
|
end;
|
|
|
|
implementation
|
|
|
|
constructor ThrRecibir.Create(usuario,host,comando,micarpeta:string);
|
|
begin
|
|
inherited Create(true);
|
|
fusuario:=usuario;
|
|
fPuerto:=PUERTO_USUARIO;
|
|
fhost:=host;
|
|
fcomando:=comando;
|
|
FreeOnTerminate:=True;
|
|
fmicarpeta:=micarpeta;
|
|
end;
|
|
|
|
procedure ThrRecibir.Execute;
|
|
const
|
|
ORD_DESCOMPRIMIR:STRING='(cd %s;tar -xvzf %s;rm %s) &';
|
|
var
|
|
fecha:string;
|
|
cardestino:string;
|
|
archivotgz:string;
|
|
orden:string;
|
|
lstream:TFileStream;
|
|
pathtgz:string;
|
|
begin
|
|
try
|
|
fecha:=formatdatetime('dd-mm',now);
|
|
archivotgz:=fusuario+'_'+fecha+'.tar.gz';
|
|
cardestino:=fmicarpeta+'/'+fecha;
|
|
if not DirectoryExists(cardestino) then
|
|
CreateDir(cardestino);
|
|
pathtgz:=cardestino+'/'+archivotgz;
|
|
fcliente:=TidTcpClient.create(nil);
|
|
lstream:= TFileStream.create(pathtgz,fmcreate);
|
|
try
|
|
sleep(3000);
|
|
fcliente.Host:=fhost;
|
|
fcliente.port:=fPuerto;
|
|
fcliente.connect;
|
|
fcliente.getResponse(200);
|
|
fcliente.SendCmd(fcomando,254);
|
|
fcliente.IOHandler.ReadStream(lstream,-1,false);
|
|
orden:=Format(ORD_DESCOMPRIMIR,[cardestino,archivotgz,archivotgz]);
|
|
fpsystem(orden);
|
|
finally
|
|
begin
|
|
fcliente.Disconnect;
|
|
fcliente.free;
|
|
lstream.free;
|
|
end;
|
|
end;
|
|
except
|
|
writeLn('Error al recibir archivo');
|
|
end;
|
|
end;
|
|
end.
|
|
|