Hello all I still cannot get my script to work with the gui windows, when the gui sub routine gets called and the windows gets created, the program freezes and script does not continue
As suggested by some I have gotten rid of the Dialog() call, and have replaced the DoEvents() call with Update(); as you can see in the script, the empty file-to-be is created..... this is the only thing that happens, then my program exits mysteriously without entering the while(1) loop which is the download progress of the file. I am left with a file-to-be of "0" bytes. Try it running the script yourself configuring it to your own ftp and see what you can make of problem. It's fairly straitforward to setup I have not done win32::Gui programming before so your help is always appreciated. See the script attached. Thankyou Jeremy
use Win32::GUI; use Win32::API; use Net::FTP; use Cwd; [EMAIL PROTECTED] = file, 0 # mode (send/recieve),1 # mode (ascii/binary),2 # ftphost, 3 # user, 4 # pass, 5 # port, 6 # passive (y/n) 7 # CWD 8 # # # #if (@ARGV) { TransferSetup(); #}else { # print "***Error: Not a StandAlone program\n"; # sleep 1; #} sub TransferSetup() { my $file = 'Killing Heidi - Mascara.mp3'; # the file to recieve my $SendRecieveMode = 'recieve'; # which way is the transfer my $TransferMode = 'asc'; # binary or ascii my $FtpHost = 'jeremy'; # hostname my $UserName = 'jeremy'; #user my $Pass = 'portbriefcase'; #pass my $Port = '21'; #port my $Passive = '0'; # 0 for nonpassive, 1 for passive my $CWD = 'D:\backup\perl stuff\perltidy-20010304\perltidy-20010304\\'; $ftp = Net::FTP->new($FtpHost, Timeout => 60) || exit; $ftp->login("$UserName","$Pass") || exit; $ftp->port($Port); if ( $TransferMode eq "bin" ) { $ftp->type(binary()); } if ($SendRecieveMode eq "recieve") { &RecieveTransfer($file,$CWD,$TransferMode); } else { die; } } sub RecieveTransfer { my $RemoteFile = $_[0]; print "$RemoteFile\n"; my $buffer=''; my $size = $ftp->size('$RemoteFile'); CreateProgressWin(); $TransferBox->Update(); my $blksize = 10240; my $track = 0; my $pos = 0; my $CurrentLocalDir = $_[1]; my $TransferMode = $_[2]; $blksize = 6240 if ( $size >= 300000 ); $TransferBox->Status->Text("Retrieving $RemoteFile..."); $TransferBox->TransferProgressBar_1->SetRange(0, 100); $TransferBox->TransferProgressBar_1->SetPos(0); $TransferBox->Size->Text("$track bytes of $size bytes received"); $TransferBox->Progress->Text(int($pos)."%"); $TransferBox->Show(); if ( TransferMode eq 'asc' ) { if (!open ( FILE, "> $CurrentLocalDir"."/".$RemoteFile )) { Msg_Box("Can't create a file to put the data for $RemoteFile: $!.",48,"Can't Create File"); return 0; } } else { if (!open ( FILE, "> $CurrentLocalDir"."/".$RemoteFile )) { Msg_Box("Can't create a file to put the data for $RemoteFile: $!.",48,"Can't Create File"); return 0; } binmode FILE; } if (! ($data = $ftp->retr($RemoteFile)) ) { Msg_Box("Can't open a data retrieval socket for $RemoteFile.",48,"Can't Open Socket"); return 0; } while(1) { $TransferBox->Update(); $TransferBox->Size->Text("$track bytes of $size bytes received"); $percent = $track/$size; $pos = 100*$percent; $TransferBox->Progress->Text(int($pos)."%"); $TransferBox->TransferProgressBar_1->SetPos($pos); $TransferBox->Update(); last unless $len = $data->read($buffer,$blksize); $track += $len; my $written = syswrite(FILE, $buffer, $len); #$TransferBox->Show(); unless(defined($written) && $written == $len) { Msg_Box("Cannot write to local file $CurrentLocalDir.\\.$RemoteFile: $!",48,"Can't Write To File"); $data->abort; $TransferBox->Hide(); close(FILE); return undef; } } $TransferBox->Hide(); $TransferBox->Update(); close(FILE); $data->close(); # implied $ftp->response return 1; } sub Msg_Box ($$$) { my ($msg, $buttons, $title) = (shift, shift, shift); return Win32::MsgBox($msg, $buttons, $title); } sub CreateProgressWin { $TransferBox = new Win32::GUI::Window( -left => 670, -top => 264, -width => 392, -height => 141, -name => "TransferBox", -text => "File Transfer" ); $TransferBox->Show(); $TransferBox->AddProgressBar( -text => "Transfer Progress", -name => "TransferProgressBar_1", -left => 13, -top => 53, -width => 356, -height => 12, ); $TransferBox->AddButton( -text => "", -name => "GroupBox_1", -left => 3, -top => 3, -width => 375, -height => 87, -style => WS_CHILD | WS_VISIBLE | 7, # GroupBox ); $TransferBox->AddButton( -text => "Kill", -name => "Cancel", -left => 352, -top => 93, -width => 29, -height => 21, -foreground => 16744448, ); $TransferBox->AddLabel( -text => "File :", -name => "Label_1", -left => 10, -top => 13, -width => 200, -height => 13, -foreground => 0, ); $TransferBox->AddLabel( -text => "Size (Bytes):", -name => "Size", -left => 11, -top => 31, -width => 200, -height => 13, -foreground => 0, ); $TransferBox->AddLabel( -text => "Progress (%) :", -name => "Progress", -left => 166, -top => 70, -width => 89, -height => 13, -foreground => 0, ); #$TransferBox->AddStatusBar( # -text => "Transfer Status:", # -name => "StatusBar_1", # -left => 0, # -top => 799, # -width => 1150, # -height => 17, # ); $TransferBox->AddButton( -text => "", -name => "transferStatus", -left => 5, -top => 88, -width => 339, -height => 24, -style => WS_CHILD | WS_VISIBLE | 7, # GroupBox ); $TransferBox->AddLabel( -text => "Transfer Status :", -name => "Status", -left => 11, -top => 96, -width => 150, -height => 13, -foreground => 0, ); #Win32::GUI::Dialog(); #return 1; } Win32::GUI::Dialog(); sub MainWindow_Terminate { return -1; } sub Cancel_Click { return -1; exit; }