Recent

Author Topic: Synapse GUI  (Read 17899 times)

cybersmyth

  • Jr. Member
  • **
  • Posts: 51
Synapse GUI
« on: January 22, 2011, 04:23:21 am »
I'm using Synapse for ftp in an app I'm working on. I was wondering if anyone had an example of gui interactions? I progress bar would be ideal.

Thanks,
-Joe

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1929
Re: Synapse GUI
« Reply #1 on: January 22, 2011, 11:51:47 am »

cybersmyth

  • Jr. Member
  • **
  • Posts: 51
Re: Synapse GUI
« Reply #2 on: January 22, 2011, 08:44:41 pm »
Thanks, but I can't figure out how that example works.  It has three parameters in the declaration, but when it's called, there are no parameters.

procedure TftpForm.SockPutCallBack(Sender: TObject;
  Reason: THookSocketReason; const Value: string);

....

ftp.DSock.OnStatus := SockPutCallBack; // Update progressbar

-Joe

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1929
Re: Synapse GUI
« Reply #3 on: January 22, 2011, 09:33:07 pm »
It's an event handler, it is not a call, you tell it which function to call in case sth. happens.

For FPC mode do this (see @)

ftp.DSock.OnStatus := @SockPutCallBack;

cybersmyth

  • Jr. Member
  • **
  • Posts: 51
Re: Synapse GUI
« Reply #4 on: January 23, 2011, 06:20:34 pm »
GREAT!  Awesome. I think I get it now. Thanks for the help.

-Joe

Lazaruszki

  • New Member
  • *
  • Posts: 10
Re: Synapse GUI
« Reply #5 on: March 07, 2011, 11:50:29 pm »
Hi cybersmyth.

Can you send me a working ftp+gui read/write example?  If it's not secret :) I try some code and look google and doc, but Lazarus always send errors.

My last idea was: Give up lazarus ...   :(  pls help!  :'(




jixian.yang

  • Full Member
  • ***
  • Posts: 173
Re: Synapse GUI
« Reply #6 on: March 08, 2011, 08:16:15 am »
procedure TForm1.Button1Click(Sender: TObject);
begin
  MailSender;
end;

procedure TForm1.OnStatus(Sender: TObject; Reason: THookSocketReason;
  const Value: string);
begin
    if (Reason = HR_WriteCount) and (StrToIntDef(Value, 0) > 10) then
    begin
      FPos := FPos + StrToIntDef(Value, 0);
      Application.ProcessMessages;
      Caption:=IntToStr(FPos);
    end;
end;

procedure TForm1.MailSender;
var
  StrList : TStringList;
  hdAttach : string;
  Mime : TMimeMess;
  SMTP : TSmtpSend;
begin

  StrList := TStringList.Create;
  Mime := TMimeMess.Create;
  SMTP := TSmtpSend.Create;
  try
    SMTP.FullSSL := True;       // Explicit
    //SMTP.AutoTLS := TRUE;     // implicit
    SMTP.TargetPort := edtPort.Text;   //SSL:465
    SMTP.UserName := edtUserID.Text;
    SMTP.Password := edtPassword.Text;
    SMTP.TargetHost := edtServer.Text;

    SMTP.Sock.OnStatus := @OnStatus;

    //SMTP LOGIN
    if not SMTP.Login then exit;

    StrList.Add(memBody.Lines.Text); 
    Mime.Header.CharsetCode := UTF_8;
    Mime.Header.From := edtFrom.Text;
    Mime.Header.ReplyTo := edtReply.Text;
    Mime.Header.ToList.Add(edtTo.Text);
    Mime.Header.CCList.Add(edtCC.Text);
    Mime.Header.Subject := edtSubject.Text;
    Mime.AddPartMultipart('', Nil);
    Mime.AddPartText(StrList, Mime.MessagePart);

    hdAttach := edtAttach.Text;
    if hdAttach <> '' then
      Mime.AddPartBinaryFromFile(hdAttach, Mime.MessagePart);

    Mime.EncodeMessage;

    if not SMTP.MailFrom(edtFrom.Text, Length(Mime.Lines.Text)) then exit;
    if not SMTP.MailTo(edtTo.Text) then exit;
    if not SMTP.MailTo(edtBCC.Text) then exit;   
    if not SMTP.MailData(Mime.Lines) then exit;

    //SMTP.Logout;
  finally
    SMTP.Logout;
    StrList.Free;
    Mime.Free;
    SMTP.Free;
  end;

end;

Lazaruszki

  • New Member
  • *
  • Posts: 10
Re: Synapse GUI
« Reply #7 on: March 18, 2011, 11:49:29 pm »
Hi Guys!

Thx fol all! The code is ready:).
It's error free:)
Ftp login : OK
It can read file name and file size from ftp server. 8-)

BUT, download file does not start. :'(

...I skip any command or don't use any function?

The code samle :


  ftp := TFTPSend.Create;
  try
    ftp.DSock.OnStatus := @SockGetCallBack; // Update progressbar
    ftp.Username := EditUser.text;
    ftp.Password := EditPassw.text;
    ftp.TargetHost := EditFtpServer.text;
    ftp.TargetPort := EditPort.text;

    //

    if ftp.Login then
      MemoLog.Lines.Add('Login:           success')
    else
    begin
      MemoLog.Lines.Add('Login:           incorrect');
      exit;
    end;

    ftp.DirectFileName := EditLocalFile.Text;
    ftp.DirectFile := true;
    TotalBytes := ftp.FileSize(EditRemoteFile.Text);

    MemoLog.Lines.Add('Load file:  ' + EditRemoteFile.Text);
    MemoLog.Lines.Add('TotalBytes: ' + IntToStr(TotalBytes));


    if ftp.RetrieveFile(EditRemoteFile.Text, false) = true then
      MemoLog.Lines.Add('Transfer completed')
    else
      MemoLog.lines.add('Transfer failed');

    ftp.Logout;
    MemoLog.Lines.Add('Connection closed');

Peter_Vadasz

  • New Member
  • *
  • Posts: 35
Re: Synapse GUI
« Reply #8 on: March 19, 2011, 08:46:18 am »
The following code works fine for me.
Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ComCtrls, ftpsend, blcksock;

type

  { TForm1 }

  TForm1 = class(TForm)
    BtnDownload: TButton;
    EditUser: TEdit;
    EditPassw: TEdit;
    EditFTPServer: TEdit;
    EditPort: TEdit;
    EditLocalFile: TEdit;
    EditRemoteFile: TEdit;
    LblRemoteFile: TLabel;
    LblUser: TLabel;
    LblLocalFile: TLabel;
    LblPassw: TLabel;
    LblFTPServer: TLabel;
    LblPort: TLabel;
    MemoLog: TMemo;
    ProgressBar: TProgressBar;
    procedure BtnDownloadClick(Sender: TObject);
    procedure SockCallBack(Sender: TObject; Reason: THookSocketReason; const Value: string);
  private
    { private declarations }
    TotalBytes : longint;
    CurrentBytes : longint;
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.BtnDownloadClick(Sender: TObject);
var ftp : TFTPSend;
begin
  Progressbar.Position:=0;
  MemoLog.Clear;
  ftp := TFTPSend.Create;
  try
    ftp.DSock.OnStatus := @SockCallBack;
    ftp.Username := EditUser.text;
    ftp.Password := EditPassw.text;
    ftp.TargetHost := EditFtpServer.text;
    ftp.TargetPort := EditPort.text;
    Application.ProcessMessages;
    if ftp.Login then
      MemoLog.Lines.Add('Login:           success')
    else
    begin
      MemoLog.Lines.Add('Login:           incorrect');
      exit;
    end;
    BtnDownload.Enabled:=False;
    ftp.DirectFileName := EditLocalFile.Text;
    ftp.DirectFile := true;
    TotalBytes := ftp.FileSize(EditRemoteFile.Text);

    MemoLog.Lines.Add('Load file:  ' + EditRemoteFile.Text);
    MemoLog.Lines.Add('TotalBytes: ' + IntToStr(TotalBytes));


    if ftp.RetrieveFile(EditRemoteFile.Text, false) = true then
      MemoLog.Lines.Add('Transfer completed')
    else
      MemoLog.lines.add('Transfer failed');
    Application.ProcessMessages;
    ftp.Logout;
    MemoLog.Lines.Add('Connection closed');
  finally
    ftp.free;
  end;
  BtnDownload.Enabled:=True;
end;

procedure TForm1.SockCallBack(Sender: TObject; Reason: THookSocketReason;
  const Value: string);
begin
  Application.ProcessMessages;
  case Reason of
    HR_ReadCount:
      begin
        inc(CurrentBytes, StrToIntDef(Value, 0));
        ProgressBar.Position := Round(1000 * (CurrentBytes / TotalBytes));
      end;
    HR_Connect: CurrentBytes := 0;
  end;
end;

end.
You can download it here: http://dl.dropbox.com/u/2766266/ftp_example.tar.gz
« Last Edit: March 19, 2011, 06:22:04 pm by Peter_Vadasz »
OS: Ubuntu 12.04.2 32 bit
Lazarus: 1.0.8
FPC: 2.6.2

 

TinyPortal © 2005-2018