on 03/16/2001 11:51 AM, Leland Beaudrot at [EMAIL PROTECTED] wrote:

> Is there something I'm missing in Net::FTP?  The script below works for
> one file but not for another.
> 
> #!/usr/in/perl
> 
> use strict;
> use Net::FTP;
> 
> my $hostname    = 'web.host.address';
> my %hostoptn    = ('Passive' => 1, 'Debug' => 1);
> my $username    = 'myusername';
> my $password    = 'mypassword';
> my $home        = 'my/home/directory';
> my $file2ftp    = 'My HD:My Folder:Another Folder:filename.html';
> my $filename    = 'filename.html';
> my $ftp        = Net::FTP->new($hostname, %hostoptn);
> $ftp->login($username, $password);
> $ftp->cwd($home);
> $ftp->ascii;
> $ftp->put($file2ftp);
> $ftp->quit;
> 
> This script works consistently for one file but not for another.  On
> failure, the server returns: "425 Data connection error".

That's easy: you're using Macintosh directory separators for what is
probably a different OS.

make sure to use the correct directory separators for the receiving end as
well as the sending end. You could also download the File::Spec module and
use that for local stuff where a script will need to be functional on two
different systems..

for example: 

#!perl -w
use strict;

# selectively silence the compile-time warning for Types.pm until someone
fixes the bloody thing :)
my $DOWARN;
BEGIN { 
    $SIG{'__WARN__'} = sub { warn $_[0] if $DOWARN };
    $DOWARN = 0; # change to 1 if you wish to test for other compile-time
warnings being present.
} 
$DOWARN = 1; # all run-time warnings still in effect.

use MacPerl qw(Answer Ask);
my $do_what = Answer('Update Map and FTP lists and download or just download
?', 'Both', 'Update', 'Download');
my $user    = Ask('Enter Username') or die "No Username Entered\n";
my $pass    = Ask('Enter Password') or die "No Password Entered\n";

if ( $do_what >= 1 ) {
    use Net::Telnet;
    print "Updating files...\n";
    my $telnet = new Net::Telnet(Timeout => 300);
    $telnet->open('hostname.com');
    $telnet->login($user, $pass);
    my @output = $telnet->cmd('~/bin/updatemaps') or die($!);
    print @output, "\n\n";
    my @output2 = $telnet->cmd('~/bin/update_database.plx') or die($!);
    print @output2, "\n\n";
    $telnet->close() or die("Error closing Telnet session: $!");
}

if ($do_what == 0 || $do_what == 2) {
    print "Downloading ...\n";
    use Net::FTP;
    my $curdir = '~/public_html/cgi-scripts/ncrp/input_files/';
    my $ftp = Net::FTP->new('hostname.com') or die ("Could not open
connection: $!");
    $ftp->login($user, $pass) or die ("Could not log in! $!");
    $ftp->ascii() or die ("could not change type to ascii! $!");
    my @files = ( "${curdir}maps_list.txt",
                  "${curdir}ftpinfo.txt",
                  "${curdir}ftpdirs_full_backup.txt" );
    $ftp->cwd($curdir) or die ("Could not change directory $!");
    foreach my $file (@files) {
        $ftp->get($file) or die ("Could not download $file! $!");
        print "$file download successful!\n";
    }
    $ftp->quit() or die("error closing FTP session: $!");
}

print 'Update completed.';
exit;
-- 
Scott R. Godin            | e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |    web : http://www.webdragon.net/


Reply via email to