Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NMFTP Issue

Status
Not open for further replies.

BuilderSpec

Programmer
Dec 24, 2003
383
GB
Hi

I am writing an app that archives files from one box to another. It connects using the NMFTP1 component and I retrieve a listing. The issue is that the listing never completes. I use the ListItem method and can get all the directory info but the call gets stuck in NMFTP->List(). I have set a timer to every 5 seconds and set a flag manually to say whether I have a directory entry .i.e has the ListItem method been called. If the timer completes and I have not seen a new directory entry in ListItem then I call NMFTP->Abort() and then Application->Terminate. HOWEVER this still does not work, the application just remains running at a high CPU rate and doesn't stop.

This is an issue I think with the box I am connecting to as I have used NMFTP loads of times successfully I am not new to it. I need to get this software to recognize that the listing has ended and move on but I can't . Any help much appreciated, full source below.


Just to emphasize the following code I think works perfectly against a "normal" windows FTP server but it hangs when I go against this other box. ( Just to clarify the other box is a bespoke hardware voice recorder that allows ftp connections , thats all I know about it ). What I am after is a way that once the Timer event spots the timeout and starts printing "Done" on the Memo for the application to just stop. By the way it does print "Done" in the Memo, it just does it every 5 seconds instead of printing it once and then exiting. I want the program to exit but it won't and that is what I really need with : how can I force my program to just stop and exit, Application->Terminate() doesn't do it in this case.



This is my form in text format :

object Form1: TForm1
Left = 304
Top = 141
Width = 696
Height = 354
Caption = 'Voice Archive'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Menu = MainMenu1
OldCreateOrder = False
Position = poDesktopCenter
PixelsPerInch = 96
TextHeight = 13
object Panel2: TPanel
Left = 0
Top = 0
Width = 680
Height = 296
Align = alClient
Caption = 'Panel2'
TabOrder = 0
object Memo1: TMemo
Left = 1
Top = 1
Width = 336
Height = 294
Align = alLeft
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Courier New'
Font.Style = []
Lines.Strings = (
'Memo1')
ParentFont = False
TabOrder = 0
end
object Memo2: TMemo
Left = 337
Top = 1
Width = 342
Height = 294
Align = alClient
Lines.Strings = (
'Memo2')
TabOrder = 1
end
end
object NMFTP1: TNMFTP
Port = 21
ReportLevel = 16
OnConnect = NMFTP1Connect
OnStatus = NMFTP1Status
OnListItem = NMFTP1ListItem
Vendor = 2411
ParseList = False
ProxyPort = 0
Passive = False
FirewallType = FTUser
FWAuthenticate = False
Left = 160
Top = 24
end
object MainMenu1: TMainMenu
Left = 216
Top = 8
object File1: TMenuItem
Caption = 'File'
object Start1: TMenuItem
Caption = 'Start'
OnClick = Start1Click
end
end
end
object Timer1: TTimer
Enabled = False
Interval = 5000
OnTimer = Timer1Timer
Left = 392
Top = 48
end
end

This is my header Unit1.h
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <NMFtp.hpp>
#include <Psock.hpp>
#include <Menus.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TPanel *Panel2;
TMemo *Memo1;
TNMFTP *NMFTP1;
TMainMenu *MainMenu1;
TMenuItem *File1;
TMenuItem *Start1;
TMemo *Memo2;
TTimer *Timer1;
void __fastcall NMFTP1Connect(TObject *Sender);
void __fastcall NMFTP1ListItem(AnsiString Listing);
void __fastcall Start1Click(TObject *Sender);
void __fastcall NMFTP1Status(TComponent *Sender, AnsiString Status);
void __fastcall Timer1Timer(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
bool RecordSeen;
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//------------------------------

This is my code unit1.cpp

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------


void __fastcall TForm1::NMFTP1Connect(TObject *Sender)
{
RecordSeen = false;
Timer1->Enabled = true;
NMFTP1->List();


}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMFTP1ListItem(AnsiString Listing)
{
Memo1->Lines->Add ( Listing );
RecordSeen = true;
Application->ProcessMessages() ;

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Start1Click(TObject *Sender)
{
NMFTP1->Host = "192.168.42.11";
NMFTP1->UserID = "0000";
NMFTP1->Password = "0000";




NMFTP1->Connect();

}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMFTP1Status(TComponent *Sender, AnsiString Status)
{
Memo2->Lines->Add ( Status );
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Timer1->Enabled = false;
if ( ! RecordSeen )
{
Memo1->Lines->SaveToFile ( "ftplist.txt");
Memo1->Lines->Add ( "Done");
try
{
NMFTP1->Abort();
}
catch(...)
{
}
Application->Terminate();
}
RecordSeen = false;

Timer1->Enabled = true;

}


Hope this helps!

Regards

BuilderSpec
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top