Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Net::FTP

by brycen (Monk)
on May 02, 2006 at 03:29 UTC ( #546808=note: print w/replies, xml ) Need Help??


in reply to Net::FTP

Is there any way to avoid a temporary file in the case where the perl script itself creates the data, e.g. something like:
$ftp->login("perl",'monk'); $ftp->put("fh.txt", <FH>); print FH qq(a,b,c,d); $ftp->quit;
And, if not, are there other perl ftp clients worth installing?

Replies are listed 'Best First'.
Re^2: Net::FTP
by Hue-Bond (Priest) on May 02, 2006 at 04:05 UTC

    DISCLAIMER: I haven't ever used Net::FTP.

    You can open scalars (v5.8.0 required) by passing a reference to that scalar to open:

    my $pseudo_file = "line1\nline2\n"; open my $rfd, '<', \$pseudo_file or die "open1: $!"; open my $wfd, '>', 'foo' or die "open2: $!"; print $wfd $_ while <$rfd>; ## or 'print $wfd (<$rfd>);' if file +isn't large close $wfd; close $rfd;

    So, according to the Net::FTP doc, I'd change your code to:

    open my $fh, '<', \$pseudo_file_already_generated or die "open: $!"; $ftp->login("perl",'monk') or die "blah"; $ftp->put($fh, 'fh.txt') or warn "blah"; $ftp->quit;

    Update: Better english.

    --
    David Serrano

      Hi,

      I am trying to implement this $ftp->login.
      But if the login is unsuccessful, I am getting the following error message and program gets terminated.
      Uncaught exception from user code: Cannot login Login incorrect.

      Is there any way to catch / handle this unsuccessful login, so that the program can continue?

        Untested:

        my $logged_in = eval { $ftp->login($un, $pw); 1; }; if (! $logged_in){ if ($@ =~ /login incorrect/i){ # do stuff, perhaps keep asking user for un/pw and # re-attempt login in a loop } else { # might not be a login error... # handle different exception } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2021-12-09 11:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (36 votes). Check out past polls.

    Notices?