Downloading 'utctf/ctf-glacier][.zip'...
Download of utctf/ctf-glacier][.zip to Secundus 8.5GB:ctf-glacier][.zip was
Successful
# Could not change file type and creator of
'Secundus 8.5GB:ctf-glacier][.zip' -- No such file or directory
File 'Primus 8.5GB:Applications:MacPerl Ÿ:NaliCity:ratings:NCGetFile'; Line
76


script follows: no clue what's causing it to 'miss' the file, although
interestingly the file DOES get set properly. Very confusing. Does
MacPerl::SetFileInfo return inverted results? 0 = true, !0 = false?

code follows:
-=--=--=--=-

#!perl -w
# NCGetFile
# last updated April 23, 2001
# $VERSION = '1.04';

use strict;
use subs qw/grab($) get_user_input($)/;
use vars qw/$downloadfile
            $localfile
            $username
            $password
            $mycwd 
            $default_download_dir/;

use Carp;
use Cwd;
use Net::FTP 2.56;
$| = 1; #pipe hot

# hard-code your preferred default download directory, if desired
# otherwise the map will arrive in the same dir as this script.
 $default_download_dir = 'Secundus 8.5GB:';

$default_download_dir ||= get_user_input(<<"DEFDIR");
your preferred download directory here,
or press [RETURN] to have maps downloaded to the same location as this
script
DEFDIR

if ($default_download_dir)
{
    die "Bad Directory name"
      unless -d $default_download_dir;
    chdir $default_download_dir
      or die "Could not change Directory: $!";

}

# grab current working directory
$mycwd = cwd;

# hard-code $username $password here if you wish,
# by uncommenting and filling in the text, or just enter on the fly
# $username = "";
# $password = "";

$downloadfile = 
    get_user_input(<<"PROMPT");
the file name that you wish to download from
ftp.planetunreal.com/cdrom/nalicity/
You _must_ include the ut*/ subdirectory, as in:
\t'utdm/dm-mapname.zip'
(Valid subdirs are utdm/, utassault/, utctf/, utdomination/, and utother/)
PROMPT

print("Leave off the initial slash, f00!\n") and $downloadfile =~ s|^/||
     if $downloadfile =~ m|^/|;

die "Include the ut*/ subdir and/or '.zip', idiot :-)"
     unless $downloadfile =~ m|^ut.+?/(.+?\.zip)|;
$localfile = $1;

# If you hard-coded your u/p above, this won't ask you again:
$username ||= get_user_input("your Username");
$password ||= get_user_input("your Password");
die "Invalid Username or Password entered" unless ($username && $password);

print "Downloading '$downloadfile'...\n";

grab($downloadfile)
 and print "Download of $downloadfile to $mycwd$localfile was Successful\n";

if ($^O eq "MacOS")
{
    # change type and creator to ZipIt format on MacOS
    require MacPerl;
    carp "Could not change file type and creator of '${mycwd}${localfile}'
-- $!"
        unless MacPerl::SetFileInfo('ZIP ', 'ZIP ', "${mycwd}${localfile}");
}

exit 0;

sub grab ($) {
    my $downloadfile = shift;
    my $curdir = '/cdrom/nalicity/';
    my $file = "${curdir}${downloadfile}";

    my $ftp = Net::FTP->new('207.199.1.129', 'timeout'=>'7500')
                             or die ("Could not open connection: $!");
    $ftp->login($username, $password) or die ("Could not log in! $!");
    $ftp->binary       or die ("could not change type to binary! $!");
    $ftp->cwd($curdir)       or die ("Could not change directory $!");
    $ftp->get($file)          or die ("Could not download $file! $!");
    $ftp->quit()            or carp ("error closing FTP session: $!");
}

sub get_user_input ($)
{
    my $prompt = shift;
    print "Enter $prompt: ";
    chomp(my $input = <STDIN>);
    print "\n";
    return $input;
}



-- 
Scott R. Godin            | e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |    web : http://www.webdragon.net/


Reply via email to