Solved

TFTP without form

Posted on 1997-05-15
6
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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 this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

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