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

I need to write a tool that includes FTP. I cannot depend on additional modules that may or may not have been downloaded from CPAN, so I'm going to assume that NET::FTP is NOT part of the PERL5 distribution that comes on our AIX boxes (BTW...how can I display a list of the modules included in the distribution?). thanks, bigtiny
  • Comment on FTP within PERL script WITHOUT NET::FTP?

Replies are listed 'Best First'.
Re: FTP within PERL script WITHOUT NET::FTP?
by kilinrax (Deacon) on Nov 13, 2000 at 20:23 UTC
    Finding out which modules are installed on your system has already been discussed here and here.
    Typing this:
    perl -MCPAN -e autobundle
    at the command line will give you a list of installed modules.

    Also:
    perl -M'[module name]' -V
    Will tell you whether a module is installed, as I previously explained here
Re: FTP within PERL script WITHOUT NET::FTP?
by wardk (Deacon) on Nov 13, 2000 at 20:32 UTC

    This should work with a gateway, this is working code with some modified names.

    my $gsRemoteMachine = "ftp.site.com"; my $gsRemoteDir = "/"; my $gsFtpId = "username"; my $gsFtpPwd = "password"; my $gsGateMachine = "gateway.site.com"; # ftp gateway my $gsGateConnect = "\@$gsRemoteMachine "; # remote machine connect +id for gateway my $gsRemoteMachine = $gsGateMachine; my $gsFeedsDir = "/mypath/"; my $gsFeedFile = "myfile"; system("ftp -n $RemoteMachine <<EOF> $StatusFile 2>&1\n\nuser $gsFtpId +$gsGateConnect $gsFtpPwd\nverbose\n$gsFtpMode\nput $gsFeedsDir$gsFeed +File $gsRemoteDir$gsFeedFile\nclose\nbye\nEOF");
    Update:Posted this real early this morning, didn't really put any meaningful comments. Note that the above is only tested on a unix box (HPUX), but should work as is on any *nix. The contents of "$StatusFile" would look about like:
    Verbose mode on.
    200 Type set to I.
    200 PORT command successful.
    150 Opening BINARY mode data connection for xxxxxxx.gz.
    226 Transfer complete.
    720203 bytes sent in 5.00 seconds (140.57 Kbytes/s)
    221- Goodbye...
    221  Total bytes retrieved: 0   stored: 720203
    

    Without Net::FTP one needs to open the $StatusFile and read it in to determine if it succeeded/failed.

    I have more on this very issue, in a previous node here Improving an FTP process that discusses FTPing this way, and why I migrated such code to Net::FTP

      The above method would probably be the best, you may want to check if you are on a Win32 or Unix platform, and call the appropriate ftp programs. If you would like to actually write your own ftp client, I don't recomend it (although it can be a good learning experiance), you should read some of the RFCs. Here is some c source code that may also help you.
Re: FTP within PERL script WITHOUT NET::FTP?
by elwarren (Priest) on Nov 13, 2000 at 22:36 UTC
    You could also take the snippet wardk posted and write it out to a .netrc file, and then execute the ftp program.
Re: FTP within PERL script WITHOUT NET::FTP?
by Fastolfe (Vicar) on Nov 13, 2000 at 23:13 UTC