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

Using Net:FTP module, I have written an automated script that will download all files (and only files) from a specified directory on a remote ftp server. My question is, how do I tell if a file on a remote server is binary or ascii? How do I get it to automatically download a file using binary or ascii mode, depending on the file type? btw, any suggestions to improve any part of this would be greatly appreciated. much thnks!
#!/usr/local/bin/perl use Net::FTP; $remote_host='x.x.x.x'; $userid='user'; $pword='password'; $remote_cwd='/export/home/user/tmp'; $local_dir='/tmp'; ## char to be parsed out, to tell if file or directory my $chr1='/'; chdir "$local_dir"; $ftp=Net::FTP->new($remote_host) or die($!); print $ftp->message(), "\n"; $ftp->login($userid,$pword); print $ftp->message(), "\n"; $ftp->binary(); print $ftp->message(), "\n"; $ftp->cwd("$remote_cwd"); print $ftp->message(), "\n"; @myfiles=$ftp->ls('-p'); # xxxxxxx parse the / out my $e; foreach $e (@myfiles) { if ($e !~ /\/\Z/) { # if (-f $e) { # print "$e\n"; $ftp->get("$e"); print $ftp->message(), "\n"; } } $ftp->close;

Replies are listed 'Best First'.
(tye)Re: Net:FTP binary or ascii?
by tye (Sage) on Mar 21, 2001 at 04:54 UTC

    Download them all as binary and ask questions later.

    For the "later" part, Perl's -B and -T provide a pretty good heuristic.

            - tye (but my friends call me "Tye")
      Thanks, I will try that. heuristic, eh?