Solved

TFTP without Form

Posted on 1997-05-15
2
224 Views
Last Modified: 2010-04-04
I encounter problems with the TFTP component:
I'm working under delphi 2.0 Client/Server, writing a console application
using the TFTP component (as an object created in the application).
Since now I never managed to even connect to my FTP server,
but by hazard, I saw that puting a messagebox call at the end of my code make
it work perfectly. I try to replace it by a sleep and so on, no one made it.
Here is my code :

program ftpsrv;

uses
  SysUtils,
  Classes,
  Windows,
  WinSvc,
  NTObj,
  SvcObj,
  DB,
  ISP,Dialogs,
  DBTables,ExtCtrls;

type TFTPc=class(TFTP)
     procedure FTPProtocolStateChanged(Sender: TObject; ProtocolState: Smallint);
end;

{$R *.RES}
var ftpc : TFTPc;
    compteur : integer;
   
{******** this event protocolstatechanged is
never called if i don't put the messagebox you'll see next **************}
procedure TFTPc.FTPProtocolStateChanged(Sender: TObject; ProtocolState: Smallint);
begin
  case ProtocolState of
    ftpBase : ftpc.Free;
    ftpAuthentication: Authenticate(UserId, Password);
    ftpTransaction: begin
                  {****** when connected I get a file to see if it works}        
            ftpc.GetFile('./docserveurNT4.htm','c:\essai.htm');
                    end;
  end;
end;

begin
{******* create the object}
ftpc:=TFTPc.Create(Nil);
{******* attach the procedure to the event}
ftpc.OnProtocolStateChanged := ftpc.FTPprotocolStateChanged;

ftpc.Password:='3il@hol.fr';
ftpc.RemoteHost:='192.9.200.2';
ftpc.RemotePort:=21;
ftpc.UserId:='anonymous';
ftpc.Connect(ftpc.remoteHost,ftpc.RemotePort);
{????????????????   here is the messagebox ?????????????}
MessageDLG('test',mtinformation,[mbOK],0);
{???????????????? if i don't put this, my file isn't downloaded, just because the
FTP client never connects. the event protocolstatechanged is never called

Please help me !!!!! 8°)
0
Comment
Question by:barrois
2 Comments
 
LVL 3

Accepted Solution

by:
sperling earned 200 total points
ID: 1336290
I assume your program exits quite soon after the MessageDlg.

If so, the TFTP component would be destroyed before it got the chance to finish connecting and downloading. Putting in a sleep will completely suspend the program, and not allow ftpc to process network data. When the sleep finishes, the program terminates before ftpc gets a chance to process the buffered data. Putting in a MessageDlg however will allow ftpc to continue working while the MessageDlg is visible, and you get the file.

Solve this by setting ftpc.Blocking := TRUE

This will cause ftpc to not return from a call before all processing has been finished.


Regards,

Erik.
0
 

Author Comment

by:barrois
ID: 1336291
thanks a lot, very usefull 8°))
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now