chimni has asked for the wisdom of the Perl Monks concerning the following question:


Hello,
I am using the attached Perl script to do FTP between two remote servers by running the script on a windows machine . The source machine for FTP is UNIX and the destination is another windows system.

When I run the code, it gives an error on line 21:
$ftpf->port($port) or die "Error sending port: $!";
use Net::FTP; # Create connections to both remote servers... $ftpf = Net::FTP->new('unix system') or die "Can't connect to 'from': +$!"; $ftpd = Net::FTP->new('windows system') or die "Can't connect to 'dest +': $!"; # ...and login to them. $ftpf->login('anonymous') or die "Can't login to 'from'"; $ftpd->login('anonymous') or die "Can't login to 'dest'"; # Place both servers into the correct transfer mode. # In this case I'm using ASCII. $ftpf->ascii() && $ftpd->ascii() or die "Can't set ASCII mode: $!"; # Send the PASV command to the destination server. # This returns a port address. $port = $ftpd->pasv or die "Can't put FTP host in passive mode: $!"; print $port; # Send the port address to the source server so it # knows where to send the data. $ftpf->port($port) or die "Error sending port: $!"; # Send the RETR and STOU commands to the servers $rfile = '/pub/swdistrib/conf/os.conf'; $ftpf->retr($rfile) or $ftpf->ok or die "Can't retrieve '$rfile': $!"; + $sfile = '/swdistrib/os.conf'; $ftpd->stou($sfile) or die "Can't store '$sfile': $!"; # Wait for the transfer to complete $ftpd->pasv_wait($ftpf) or die "Transfer failed: $!"; $ftpd->close() && $ftpf->close() or die "Can't close connections: $!"; + $ftpf->quit() && $ftpd->quit() or die "Can't quit ftp connections: $!" +;

The error says "Error sending port".$! just gives the line num
What could be the possible cause for this error? Regards chimni
UPDATE: I run the script as admin on my local machine.
MR.Muskrat your change worked for me.Thanks.
  • Comment on Net:FTP: between unix and windows host launched from another windows host
  • Download Code

Replies are listed 'Best First'.
Re: Net:FTP:Recursive: between unix and windows host launched from another windows host
by Mr. Muskrat (Canon) on Mar 26, 2004 at 04:48 UTC

    Why can't you get the port number before trying to connect? Untested:

    use Net::FTP; $ftpd = Net::FTP->new('windows system') or die "Can't connect to 'dest +': $!"; $ftpd->login('anonymous') or die "Can't login to 'dest'"; $ftpd->ascii() or die "Can't set ASCII mode: $!"; $port = $ftpd->pasv or die "Can't put FTP host in passive mode: $!"; print $port; $ftpf = Net::FTP->new('unix system', port => $port) or die "Can't conn +ect to 'from': $!"; $ftpf->login('anonymous') or die "Can't login to 'from'"; $ftpf->ascii() or die "Can't set ASCII mode: $!"; $rfile = '/pub/swdistrib/conf/os.conf'; $ftpf->retr($rfile) or $ftpf->ok or die "Can't retrieve '$rfile': $!"; + $sfile = '/swdistrib/os.conf'; $ftpd->stou($sfile) or die "Can't store '$sfile': $!"; $ftpd->pasv_wait($ftpf) or die "Transfer failed: $!"; $ftpd->close() && $ftpf->close() or die "Can't close connections: $!"; + $ftpf->quit() && $ftpd->quit() or die "Can't quit ftp connections: $!" +;

    Update: removed redundant ascii call

Re: Net:FTP: between unix and windows host launched from another windows host
by TilRMan (Friar) on Mar 26, 2004 at 06:18 UTC

    Net::FTP won't populate $! with error information. Turn on debugging (see the synopsis) and see what happens.

    -- 
    LP^>

      Hi, I was having the same error on the port, so I declared the port before login to the remote server. But now I get this other error on the # Wait for the transfer to complete $ftpd->pasv_wait($ftpf) or die "Transfer failed: $!"; Transfer Failed. What else could be wrong? Thanks,
Re: Net:FTP: between unix and windows host launched from another windows host
by diskcrash (Hermit) on Mar 26, 2004 at 06:11 UTC
    Depending upon the port number coming back (which might be some high numbered oddball) you might need administrator privs to run it. You might need them anyway. What context does this run in?

    diskcrash