Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Re: Who needs files? Net::FTP::Scalar (code)

by staunch (Pilgrim)
on Dec 13, 2001 at 22:36 UTC ( #131692=note: print w/replies, xml ) Need Help??

in reply to Re: Who needs files? Net::FTP::Scalar (code)
in thread Who needs files? Net::FTP::Scalar (code)

Although LWP::* can do FTP as I found out. And that is probably the recommended way to go. I had already basically finished this by the time I figured that out
So I'm going to post it here, for comments, or whatever.

Default mode is to download in Binary, you can specify Ascii like this:
my($file) = get(";type=a");

Here is

package Net::FTP::Simple; require Exporter; use strict; use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION); @ISA = qw(Exporter); @EXPORT = qw(); @EXPORT_OK = qw(get); $VERSION = '0.01'; use URI; use Net::FTP::Scalar; $Net::FTP::Scalar::SCALAR_MODE = 1; sub get { my($url) = shift(); my($uri) = URI->new($url); my($user) = $uri->user(); my($pass) = $uri->password(); my($host) = $uri->host(); my($port) = $uri->port(); my($ftp) = Net::FTP::Scalar->new($host, Debug => 0) || warn("new() + '$host' failed: $@") && return(); $ftp->login($user, $pass) || warn("login() '$user' failed: $@") && + return(); my(@path) = grep { length() } $uri->path_segments(); my($file) = pop(@path); my($type); if (ref($file)) { my(@params); ($file, @params) = @$file; foreach (@params) { $type = $_ if (s/^type=//); } } if (defined($type) && $type eq 'a') { $ftp->ascii(); } else { $ftp->binary(); } foreach (@path) { $ftp->cwd($_) || warn("cwd() '$_' failed: $@") && return(); } unless ($ftp->get($file)) { $ftp->quit(); warn("get() '$file' failed: $@"); return(); } return($Net::FTP::Scalar::OUT_FILE); } return(1);


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://131692]
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: (7)
As of 2021-12-09 08:23 GMT
Find Nodes?
    Voting Booth?
    R or B?

    Results (36 votes). Check out past polls.