Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Net::FTP and putting errors to STDOUT???

by drock (Beadle)
on Sep 17, 2004 at 17:23 UTC ( #391846=perlquestion: print w/replies, xml ) Need Help??

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

All How can I put any errors to STDOUT or in the case $ftplog, with a Net::FTP block? This is currently not putting anything to my $ftplog file. Here is my code:
sub ftpme { my $remotehost="ftp.foo.com"; my $remotedir="archive"; my $user="xxxxx"; my $pass="xxxxxx"; my $data=$scratchtps; my $ftplog="/usr/local/log/ftp_IrMt_scratchtapes.log"; my $ftp = Net::FTP->new($remotehost, Debug => 10) || die "Cannot connect to $remotehost: IronMt: $!, pri +nt ($ftplog)"; $ftp->login($user, $pass) or die "Login failed!: $!, p +rint ($ftplog)"; $ftp->ascii(); $ftp->cwd($remotedir); $ftp->put($data) or die "FTP put to IrMt failed!: $!, +print ($ftplog)"; $ftp->quit; }

Replies are listed 'Best First'.
Re: Net::FTP and putting errors to STDOUT???
by ikegami (Patriarch) on Sep 17, 2004 at 17:27 UTC

    This might do the trick:

    sub ftpme { my $remotehost="ftp.foo.com"; my $remotedir="archive"; my $user="xxxxx"; my $pass="xxxxxx"; my $data=$scratchtps; local *FTPLOG; open(FTPLOG, ">>/usr/local/log/ftp_IrMt_scratchtapes.l +og") or die("Can't open log file"); my $ftp = Net::FTP->new($remotehost, Debug => 10) or do { print FTPLOG "Cannot connect to $remotehost: I +ronMt: $!"; die(); }; $ftp->login($user, $pass) or do { print FTPLOG "Login failed!: $!"; die(); }; $ftp->ascii(); $ftp->cwd($remotedir); $ftp->put($data) or do { print FTPLOG "FTP put to IrMt failed!: $!"; di +e(); }; $ftp->quit; }
      cool...thanks! What is the * next to the FTP filehandle represent?

        Similiar to $ = scalar, @ = array, % = hash and & = code, there is a -what's-the-word- for symbol table entries and file handles: *.

        print("1\n"); open(HANDLE, '<', 'lines.txt') or die("!1\n"); print(scalar(<HANDLE>)); close(HANDLE); print("\n"); print("2\n"); $h = *HANDLE; open($h, '<', 'lines.txt') or die("!2\n"); print(scalar(<HANDLE>)); print(scalar(<$h>)); close($h); print("\n"); print("3\n"); $h = \*HANDLE; open($h, '<', 'lines.txt') or die("!3\n"); print(scalar(<HANDLE>)); print(scalar(<$h>)); close($h); print("\n");

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://391846]
Approved by sintadil
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (1)
As of 2023-01-29 06:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?