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

net::ftp please

by Anonymous Monk
on Apr 18, 2001 at 03:34 UTC ( [id://73390]=perlquestion: print w/replies, xml ) Need Help??

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

<http> <body> Hi.. soo.. i created a simple .pl script and run it from
the browser window. I removed the put line, and am just
attempting to get a file from my hosting site and have it
land on my hard drive. Of course i get the stupid internal server error.
Made sure privileges are set correctly.
I searched Verio and could only find ftp.pm,
not net::ftp.. but i heard it's the same thing. Any hints
what might be going on? Thanx...

Lisa.
use NET::FTP; my $hostname='superwarez.com'; my $user='warez'; my $password='warez'; my $ftp=Net::FTP -> new($hostname) or die ("Connect failed"); $ftp->login($username,$password); $ftp->binary; $ftp->cwd("/pub/uploads"); $ftp->put("mystuff.txt"); $ftp->get("warezlist.txt"); $ftp->quit

Replies are listed 'Best First'.
Re: net::ftp please
by arturo (Vicar) on Apr 18, 2001 at 03:46 UTC

    A couple of things to keep in mind: Perl is a case sensitive language. "NET::FTP" is not the same thing as "Net::FTP", so that line as you have it won't work. And if this is for a warez site, I'm not sure I should go on much further, but ... in the interests of showing you the joy of Free software (as in speech) and possibly turning you to the Light side of the Force ... =)

    Secondly: there's a procedure for installing Perl modules, you usually can't just copy a file onto your system and have it work just like that. There are specific locations where the files go, and so forth. Fortunately, there are tools that handle a lot of this for you. There is also a wonderful site known as CPAN through which most Perl modules worth having are available.

    First check to see whether Net::FTP is already installed on the system:

    perl -MNet::FTP
    should be sufficient for this purpose. If it isn't ...well, you could ask your hosting company (be sure to tell them that it's for managing a warez site) to install the module so everyone can use it, or you could install it into a directory where you have write privileges (usually, $HOME/perllib or something like that suffices).

    For instructions on installing modules, see perldoc perlmod and perldoc perlmodinstall and do some searching on this site ('install module' is a good place to start with search terms).

    HTH

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

      <http> <body> I made the change from NET to Net::ftp, but no luck. I think verio does not have the Net::FTP module.. and ftp.pm is not the same thing. I just wanted to make sure that i could run a simple .pl script in a browser window and expect it to work. Only other question i have is.. how do you know where the file is going to land on hard drive? That's about it.. i'll do some more reading and testing.. i wish i had my own linux server. :)

      Lisa.
Re: net::ftp please
by Adam (Vicar) on Apr 18, 2001 at 04:46 UTC
    Net::FTP is actually part of the libnet distribution. The module is actually pretty solid, except that you have to check the return codes after every call. (I'm not a real fan of that style of code.) This is done by calling $ftp->ok() after every other $ftp call. The actual message is in two parts, code() and message(). So you end up doing:
    use strict; use Net::FTP; my $ftpSite = "ftp.somesite.net"; my $username = "..."; my $password = "..."; my $ftp = Net::FTP->new( $ftpSite ) or die "No connect to '$ftpSite' : $@"; $ftp->login( $username, $password ); die $ftp->code(), ": ", $ftp->message() unless $ftp->ok(); # and so on...
    I usually write a status method that retrieves and prints the status messages regardless of any errors, and then hiccups when not $ftp->ok(). So my code reads $ftp->func(); check( $ftp ); over and over again. But the end result is well worth it.

    I hope that helps.

Re: net::ftp please
by AgentM (Curate) on Apr 18, 2001 at 03:47 UTC
    You've been asking lots of questions but haven't been doing lots of listening. It has been already explained to you that ftp.pm is in the Net directory, which makes it Net::FTP. Could the capitalized (hence non-existent) module be the problem?
    AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.
      <http> <body> Let's say instead of Net::ftp, i use ftp.pm since that's
      all verio seems to have.. here's the module link:
      http://home.verio.com/support/hosting/perl_modules.cfm
      So how would the first line of the script look? Should i
      still use the double colons.. :: ..?

      Lisa.

      use NET::FTP;
      my $hostname='Lisa.com';
      my $user='Lisa';
      my $password='Lisa';
      my $ftp=Net::FTP -> new($hostname) or die ("Connect failed");
      $ftp->login($username,$password);
      $ftp->binary;
      $ftp->cwd("/pub/uploads");
      $ftp->put("mystuff.txt");
      $ftp->get("warezlist.txt");
      $ftp->quit
        The "Net" before the colons indicates that the module is in the Net directory. If the module you want, say "Bubba.pm" is in the "Slurpy" directory, then you allow yourself to use it with
        use Slurpy::Bubba;
        If Bubba is in a Perl "main" directory, then it finds it when you write "use Bubba". If you insist that there is no "Net::FTP" module that you can use, I would 1) throw my hand in the air and "use FTP;" and 2) consider switching servers to someplace that knows something more about Perl dependencies.
        AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.

        As many people seem to have pointed out to you, it should be:

        use Net:FTP;

        Not, NET::FTP, or Net::ftp or any of the other variations that you've tried. Perl is case sensitive, so nothing else will work.

        --
        <http://www.dave.org.uk>

        "Perl makes the fun jobs fun
        and the boring jobs bearable" - me

Re: net::ftp please
by diskcrash (Hermit) on Apr 18, 2001 at 04:36 UTC
    Am I missing something? You set $user='warez' but then use $username in the login call.

    -diskcrash

      <http> <body> No... the script is just a template.. it's not the real script.. like i'm sure i'm going to type my real username and password.. I may not be very good at perl.. but i'm not a complete idiot.

      -Lisa
        What I meant was $user is not $username. If this is just a typo from the "template", fine. How about the real code, but with stubbed out user content?

        -diskcrash

Re: net::ftp please
by stefan k (Curate) on Apr 18, 2001 at 13:11 UTC
    I'm not getting into this discussion any deeper but I'd like to point you to
    use CGI::Carp qw/fatalsToBrowser/;
    so that you can get the errormessages in your browser window (unless your provider puts some kind of wrapper around all scripts)

    Regards Stefan K

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-19 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found