Italian community of Lazarus and Free Pascal

Programmazione => Componenti Aggiuntivi => Topic aperto da: Maverich - Luglio 23, 2012, 12:23:36 pm

Titolo: uso di iNet o Synapse al posto di Indy
Inserito da: Maverich - Luglio 23, 2012, 12:23:36 pm
Indy 10 non funziona su Win7 64 (TCP connect).

ho provato iNet, presente in CodeTyphon, e a parita di Host e Porta 21 si connette.
ora ho il problema dei comandi per inviare e ricevere files

- problema 1 - la funzione Autenticate risponde sempre True anche con user e pwd sbagliate
- problema 1 - i files sul server non arrivano

sul component FTP ho i metodi
.Send(const : aData; const Size: Integer; aSocket:TSocket= nil)
.Put(nomefile)

es:
  LFTPClientComponent1.Connect('ftp.webalice.it', 21);
  LFTPClientComponent1.Binary := True;
  if LFTPClientComponent1.Authenticate('user', 'pwd') then
  begin
   if LFTPClientComponent1.ChangeDirectory('/WA/Test1') then
     begin
       if LFTPClientComponent1.Put('D:\Lazarus\Test\TestLaz\oci.dll') then
          Label1.Caption := 'ok';
     end;
  end;
  LFTPClientComponent1.Disconnect(True);
  Label1.Refresh;

il file sul server non e' presente
mi interressa verificare quanti byte sono stati inviati (visualizzare il dato in una progressbar)

trovo 2 eventi OnSent e OnSuccess

procedure TForm1.LFTPClientComponent1Sent(aSocket: TLSocket;
  const Bytes: Integer);
begin
  // da qui non passa
end;

ho cercato esempi su iNet ma niente, e su Synapse idee ?
Titolo: Re:uso di iNet o Synapse al posto di Indy
Inserito da: Maverich - Luglio 23, 2012, 03:14:08 pm
tramite la libreria Synapse FtpSend si possono Ricever/Inviare file da e verso un Server ftp
http://wiki.lazarus.freepascal.org/Synapse#Overview

..uses FtpSend

  Result := FtpPutFile(Host, IntToStr(Port), Source, TargetFile, 'user', 'pwd');
  Result := FtpPutFile(Host, IntToStr(Port), Source, TargetFile, 'user', 'pwd');

resta il problema di sapere i bytes inviati / ricevuti
ma non essendo  un componente visuale niente eventi.
Titolo: Re:uso di iNet o Synapse al posto di Indy
Inserito da: Stilgar - Luglio 23, 2012, 03:59:08 pm
Al posto di usare la funzione, usa la classe, mi sembra di ricordare che permette di avere un feedback che fa al caso tuo.
Titolo: Re:uso di iNet o Synapse al posto di Indy
Inserito da: Maverich - Luglio 23, 2012, 04:50:30 pm
la classe a cui ti riferisci direi che sia TFTPSend

questa ha il metodo
function RetrieveFile(const FileName: string; Restore: Boolean): Boolean; virtual;

 clFtp := TFTPSend.Create;

  Result := clFtp.RetrieveFile('/WA/Immagini/disposizione Delphi.jpg', False);
  clFtp.OnStatus := qualcosa

Retrievefile non ha informazioni su DataSocket .

function TFTPSend.RetrieveFile(const FileName: string; Restore: Boolean): Boolean;
var
  RetrStream: TStream;
begin
  Result := False;
  if FileName = '' then
    Exit;
  if not DataSocket then     **** non trova ed esce
    Exit;
  Restore := Restore and FCanResume;
Titolo: Re:uso di iNet o Synapse al posto di Indy
Inserito da: bonmario - Luglio 23, 2012, 07:32:49 pm
Non mi è mai servito, ma in Synapse, nell'oggetto THTTPSend c'è questo:
Codice: [Seleziona]
    {:if this value is not 0, then data download pending. In this case you have
     here total sice of downloaded data. It is good for draw download
     progressbar from OnStatus event.}
    property DownloadSize: integer read FDownloadSize;

    {:if this value is not 0, then data upload pending. In this case you have
     here total sice of uploaded data. It is good for draw upload progressbar
     from OnStatus event.}
    property UploadSize: integer read FUploadSize;
    {:Socket object used for TCP/IP operation. Good for seting OnStatus hook, etc.}
    property Sock: TTCPBlockSocket read FSock;                                     

Credo che facciano al caso tuo.

Ciao, Mario
Titolo: Re:uso di iNet o Synapse al posto di Indy
Inserito da: Maverich - Luglio 24, 2012, 10:20:28 am
Avevo fatto tutto con Indy 10 (li uso in Delphi e quindi mi era stato facile), ma ora probabilmente causa una rel piu' aggiornata ... 10.5.x , non funziona piu' neppure agganciando un Server Linux Ftp; (la versione Delphi funziona ancora correttamente);
ho fatto un test su Lazarus liscio con Indy 10.2.0.3 e la connessione avviene, pero' nessuno garantisce che nell rel. successive possa continuare a funzionare , quindi ho scelto di passare a Synapse.
Sono quasi riuscito a fare quello che serve, eccetto questo dannato OnStatus ...;
Portate pazienza se rompo...

la libreria FtpSend sarebbe piu' idonea sia per leggere una Directory dsl Server Ftp
che per trasferire file tra 2 server
function FtpInterServerTransfer( const FromIP, FromPort, FromFile, FromUser, FromPass: string; const ToIP, ToPort, ToFile, ToUser, ToPass: string): Boolean;
//A very useful function, and example of use can be found in the TFtpSend object. Initiate transfer of file between two FTP servers.

mi resta il problema di come indirizzare l'Evento OnStatus che mi restituisce sempre errore (forse non corrisponde il prototipo di chiamata)
posto le modifiche fatte anche seguendo un'esempio Synapse
http://www.ararat.cz/synapse/doku.php/public:howto:onstatus

//evento per esecuzioine Status della classe CallBack
FTPS.DSock.OnStatus := CallBack.Status; 

unit1.pas(226,41) Error: Wrong number of parameters specified for call to "Status"
Codice: [Seleziona]
uses
 ..., FtpSend,  typinfo, blcksock;
dichiaro la classe di appoggio
Codice: [Seleziona]
  type
    THookSocketStatus = procedure(Sender: TObject; Reason: THookSocketReason; const Value: string) of object;

    { Callback }

    Callback = class
      class procedure Status (Sender: TObject; Reason: THookSocketReason; const Value: String);
  end;
la procedure Status
Codice: [Seleziona]
{ Callback }

class procedure Callback.Status(Sender: TObject; Reason: THookSocketReason;
  const Value: String);
var v: String;
  begin
    v := getEnumName (typeinfo(THookSocketReason), integer(Reason)) + ' ' + Value;
    Form1.Memo1.Lines.Add(v);
    if (reason=hr_writecount) then
    inc(SizeOUT,StrToInt64Def(Value,0));
    Form1.Label1.Caption:=inttostr(SizeOUT);
    application.ProcessMessages;
end;
creo l'istanza a FtpSend
Codice: [Seleziona]
procedure TForm1.FormCreate(Sender: TObject);
begin
  FTPS:= TFTPSend.Create;
end;
ed infine l'esecuzione del trasferimento file e assegnazione Evento
Codice: [Seleziona]
procedure TForm1.Button3Click(Sender: TObject);
var
  bEsito: boolean;
  Source, TargetFile: string;
  Reason: THookSocketReason;
begin
  SizeIN:=0;
  SizeOUT:=0;
  FTPS.TargetHost:= 'ftp.webalice.it';
  FTPS.TargetPort := '21';
  FTPS.UserName := 'user';
  FTPS.Password := 'pwd';
  FTPS.DSock.SendMaxChunk := 8192;

  if not FTPS.Login then Form1.Caption:= 'Not Connected';

  //evento per esecuzioine Status della classe CallBack
  FTPS.DSock.OnStatus := CallBack.Status; 
  Source := '/WA/Immagini/readme_fr.htm';
  TargetFile := 'D:\Temp\Test\Messaggi.jpg';

  Result := FtpGetFile('ftp.webalice.it', '21', Source, TargetFile, 'user', 'pwd');
end;
sempre da quell'esempio trovo
Codice: [Seleziona]
 attaching this callback to a socket:

Sock := T[UDP/TCP/..]BlockSocket.Create;
Sock.OnStatus := callback.Status;
ma non capissco Sock := T[UDP/TCP/..]BlockSocket.Create;
cosa assegnano con T[UDP/TCP/..]
Titolo: Re:uso di iNet o Synapse al posto di Indy
Inserito da: Stilgar - Luglio 24, 2012, 10:26:14 am
Citazione
ma non capissco Sock := T UDP/TCP/..BlockSocket.Create;
 cosa assegnano con T UDP/TCP/..
[/quote]
Per rispondere ad istinto ... TUDPBlockSocket o TTCPBlockSocket o altro tipo di "BlockSocket"
Titolo: Re:uso di iNet o Synapse al posto di Indy
Inserito da: Maverich - Luglio 30, 2012, 02:30:20 pm
... hanno rilasciato CT 2.80 con le nuove Indy 10.5.8.8
il componente TCP con la nuova rel. funziona correttamente.