Recent

Author Topic: [SOLVED] LNet and FTP  (Read 3631 times)

Swirl

  • New Member
  • *
  • Posts: 24
[SOLVED] LNet and FTP
« on: February 06, 2018, 11:43:08 am »
Hi Folks

still got problems to get my file transfer with LNET (0.6.5) and FTP running. (sorry Almindor...)

I tried to follow Almindors/your advice but I did not succeed:
Quote
Client FTP is more or less like this:

FTP.Connect; // say we specified the ip and port in
either OnError or OnConnect gets called, depending on if we connected or not.
If we connected, in the OnConnect, you should issue the authentication commands
Either OnFailure or OnSuccess will get called based on the auth result
(make sure you have the auth commands in the StatusSet property, otherwise it won't be reported)

As for sending, you should use OnCanSend as I wrote above in my previous post. Hope this helps.

According to my understanding I tried to "file transfer" as mentioned above using the FTP component.

First Event (just clicking button to start)
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   FTP.Connect('myhost.de', 21);
  4. end;

Second event
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FTPConnect(aSocket: TLSocket);
  2. begin
  3.   FTP.Authenticate('user', 'password');
  4.   ftp.ChangeDirectory('ftptest');
  5. end;
   

Third event (never fired!)
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FTPSuccess(aSocket: TLSocket; const aStatus: TLFTPStatus);
  2. begin
  3.   ftp.Binary := true;
  4.   if FTP.Put('d:\swirl\projects\ftp\apple.png') then beep;
  5. end;

StatusSet: all checked TRUE...

I also traced  FTPError and FTPFailure: never fired...

I'd be glad if anybody could help.

Regards
Mike
« Last Edit: February 08, 2018, 04:01:34 pm by Swirl »
Working with Lazarus 2.0.12 - FPC 3.2.0 on Win/Mint/elementaryOS
Playing with Lazarus on macOS 10.15 / Catalina

Swirl

  • New Member
  • *
  • Posts: 24
LNet and FTP
« Reply #1 on: February 07, 2018, 11:30:09 am »
Does really nobody have a clue?

Mike  :-\
Working with Lazarus 2.0.12 - FPC 3.2.0 on Win/Mint/elementaryOS
Playing with Lazarus on macOS 10.15 / Catalina

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: LNet and FTP
« Reply #2 on: February 07, 2018, 12:25:49 pm »
Try to add an event for FTPControl:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FTPControl(aSocket: TLSocket);
  2. var
  3.   s: string;
  4. begin
  5.   if FTP.GetMessage(s) > 0 then begin
  6.     Memo1.Lines.Append(s);
  7.     Memo1.SelStart := Length(Memo1.Text);
  8.   end;
  9. end;

Somehow you need to read the FTPs messages before the other events work correctly

B.T.W. there is a complete FTP example program at lnet\examples\visual\ftp.
« Last Edit: February 07, 2018, 12:29:48 pm by rvk »

Swirl

  • New Member
  • *
  • Posts: 24
Re: LNet and FTP
« Reply #3 on: February 07, 2018, 01:31:00 pm »
Thanks rvk

that takes me one step further. Calling "FTPControl" now causes "FTPFailure"
to fire and I can dig now in the right direction...


Memo tells me:

   220 FTP Server ready.
   502 'CWD': command not implemented.
   331 Password required for u55394254
   230 User u55394254 logged in
   250 CWD command successful
   550 ftptest: No such file or directory
   250 CWD command successful
   550 ftptest: No such file or directory
   200 Type set to I
   *** and so on ***
   550 ftptest: No such file or directory
   200 Type set to I

"502 'CWD': command not implemented" versus "250 CWD command successful"
confuses me a little bit, and I think there is a wrong order in submitting commands.

I know there is an ftp example in the component directory, but analyzing code is not
my major ability. Anyway I'll have a look at it now...

Regards
Mike
« Last Edit: February 07, 2018, 01:40:10 pm by Swirl »
Working with Lazarus 2.0.12 - FPC 3.2.0 on Win/Mint/elementaryOS
Playing with Lazarus on macOS 10.15 / Catalina

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: LNet and FTP
« Reply #4 on: February 07, 2018, 05:19:42 pm »
You are FTP.Put'ing a file on EVERY FTPSuccess. But FTPSuccess is triggered a lot more than you expect.

Try this and you'll understand:

Code: Pascal  [Select][+][-]
  1. uses TypInfo;
  2.  
  3. procedure TForm1.FTPSuccess(aSocket: TLSocket; const aStatus: TLFTPStatus);
  4. begin
  5.   Showmessage('Success ' + GetEnumName(TypeInfo(TLFTPStatus), Ord(aStatus)));
  6.   //ftp.Binary := true;
  7.   //if FTP.Put('d:\swirl\projects\ftp\apple.png') then beep;
  8. end;
  9.  

You shouldn't call FTP.Put() when you are even in fsConn state.

 

TinyPortal © 2005-2018