hi I have a ftp script that i have been testing on my own machine. It works when i try it on my ftp server on my computer, but it does not work when on any server that is not mine.
I feel it is the $ftp->size() that does not register when i logon to a remote site whether it be a microsoft, freebsd or linux server.....it gives me no value for the size of the given file...without this i cannot download, as i have setup my transfers not using the get() command, but using the $ftp->retr for the purpose of displaying the gui progress bar of the transfer. try the attached script....just run it, it will log you on to anomynously to ftp.microsoft.com and attempt to download a file. it will display debugging messages such as "cannot get filesize "
use Win32::GUI; use Win32::API; use Win32; 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 = 'macosplayer3.1b1c7.hqx'; # the file to recieve my $SendRecieveMode = 'recieve'; # which way is the transfer my $TransferMode = 'asc'; # binary or ascii my $FtpHost = 'ftp.microsoft.com'; # hostname my $UserName = 'anonymous'; #user my $Pass = '[EMAIL PROTECTED]'; #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, Passive => 1) || exit; $ftp->login("$UserName","$Pass") || die "cant login"; $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) || print "cannot get file size!"; CreateProgressWin(); Win32::GUI::DoEvents(); my $blksize = 10240; my $track = 0; my $pos = 0; my $CurrentLocalDir = $_[1]; my $TransferMode = $_[2]; $blksize = 6240 if ( $size >= 300000 ); $TransferBox->Label_1->Text("$RemoteFile"); $TransferBox->Status->Text("Retrieving $RemoteFile..."); $TransferBox->TransferProgressBar_1->SetRange(0, 100); $TransferBox->TransferProgressBar_1->SetPos(0); $TransferBox->Size->Text("$track bytes of $size bytes"); $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() { last if Win32::GUI::DoEvents() < 0; $TransferBox->Size->Text("$track bytes of $size bytes"); $percent = $track/$size; $pos = 100*$percent; $TransferBox->Progress->Text(int($pos)."%"); $TransferBox->TransferProgressBar_1->SetPos($pos); $TransferBox->DoEvents(); 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(); Win32::GUI::DoEvents(); 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 => 250, -height => 13, -foreground => 0, ); #Win32::GUI::Dialog(); #return 1; } Win32::GUI::Dialog(); sub MainWindow_Terminate { return -1; } #Win32::GUI::Dialog(); sub Cancel_Click { return -1; #exit; }