Solved

TFTP without form

Posted on 1997-05-15
6
266 Views
Last Modified: 2012-05-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:apostoly
  • 5
6 Comments
 

Expert Comment

by:chrb
ID: 1336284
Hi!

>ftpc:=TFTPc.Create(Nil);
Try this :
 ftpc:=TFTPc.Create(Application);

If it dosn't work try something like this :
 ftpc:=TFTPc.Create([Name of your form]);

Good luck :)

Chr
0
 

Author Comment

by:apostoly
ID: 1336285
not good answer the question is without a Form nor a TApplication
0
 

Expert Comment

by:chrb
ID: 1336286
Sorry,
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Expert Comment

by:chrb
ID: 1336287
Sorry.
0
 

Accepted Solution

by:
chrb earned 0 total points
ID: 1336288
Now I tried it in Delphi, didn't do that last time. But now it works :)

This work fine with me :

program ftpsrv;

uses
 SysUtils,
 Classes,
 Windows,
{ WinSvc,
 NTObj,
 SvcObj,}  { I Havn't client/server}
 DB,
 ISP,Dialogs,
 DBTables,ExtCtrls;

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

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('/w95files/patch/tray.zip','c:\tray.zip');
 end;
 end;
end;

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

ftpc.Password:='lboehn@online.no';
ftpc.RemoteHost:='www.sentralen.com';
ftpc.RemotePort:=21;
ftpc.UserId:='anonymous';
ftpc.Connect(ftpc.remoteHost,ftpc.RemotePort);
{???????????????? here is the messagebox ?????????????}
MessageDLG('test',mtinformation,[mbOK],0);
end.

Hope you get it working now :-)
0
 

Expert Comment

by:chrb
ID: 1336289
Did it works?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

705 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

15 Experts available now in Live!

Get 1:1 Help Now