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

I recently needed to download a couple hundred jpegs from a server that were all numbered consecutively (i.e. 456.jpg, 457.jpg). Thinking I was pretty clever, I Wrote a script using the Net::Ftp module to get files 384-503, and 505-650. The Code is right here:
use Net::FTP; my $file; $ftp = Net::FTP->new("ftp.xoom.com", Debug => 0); $ftp->login("username",'password'); print "logged in\n"; $ftp->cwd("/img"); for($file = 384; $file<651 ; $file++) { if($file != 504) { $ftp->get("$file.jpg"); print "got $file.jpg\n"; } } $ftp->quit;
I got all of the files, but when I tried to open them, they were just bands of colors instead of the pictures that I wanted. If anyone has any ideas/solutions, I'd like to know where I went wrong.
- p u n k k i d

Replies are listed 'Best First'.
Re: Using Net::Ftp
by ColtsFoot (Chaplain) on Jul 26, 2000 at 16:02 UTC
    I have not often used Net::FTP but perhaps you should have called
    the "type" method to change the transfer mode to binary.
    type (TYPE [, ARGS]) This method will send the TYPE command to the remote FTP server to +<BR> change the type of data transfer. The return value is the previous va +lue
RE: Using Net::Ftp
by eduardo (Curate) on Jul 26, 2000 at 16:54 UTC
    once again, perlmonks becomes the site whereby people ask: "i have to write a recursive web (or ftp) based porn grabber..." what is the proper way to do this? :) well, all of the answers up there are right, you need to set type to binary... however, my question is, why don't you just use mget?
      how do you use mget with net::ftp? when I try it, it cries about not being able to recognize it. any ideas? bill
RE: Using Net::Ftp
by mrmick (Curate) on Jul 26, 2000 at 18:23 UTC
    I copied the following from the man page:
    type (TYPE [, ARGS]) This method will send the TYPE command to the remote FTP server t +o change the type of data transfer. The return value is the previous value. ascii ([ARGS]) binary([ARGS]) ebcdic([ARGS]) byte([ARGS]) Synonyms for type with the first arguments set correctly NOTE ebcdic and byte are not fully supported.
    Set the type to binary for images. Usually the default is ascii and your image file will end up as garbage once it is downloaded to your end unless the type is changed.

    I hope this helps.

    Mick
Re: Using Net::Ftp
by c-era (Curate) on Jul 26, 2000 at 16:04 UTC
    I'm not too familuar with net::ftp, but you need to switch to binary mode when recieving jpgs. I beleve the command is "$ftp->binary()", but if I am wrong I'm shure someone will correct me ;)