河野真治 @ 琉球大学情報工学です。

In article <JUN.05Jun10102349@nih.go.jp>, jun@nih.go.jp writes
> Net::FTPを使って、壁の内側にあるFTPサーバーにアクセスするウェブ
> インターフェイスをCGIで作ろうとしています。ディレクトリをブラウ
> ズして、最終的にファイルをgetしたいのですが、Net::FTPのgetだと、
> 対象のファイルはローカルディスク、つまりCGIスクリプトが実行され
> ているウェブサーバーのディスクに保存されてしまいます。

/dev/stdout とかを指定してもだめですか? get を見る限り、
いけそうな気がする。

> たいです。Net::FTPにはcatは無いようですし、どのようにしたらいい
> のでしょうか? perlのバージョンはv5.8.5 built for i386-freebsd-64intです。

cat か。作っても簡単みたいですけど。

テストしてません。ごめんなさい。

    package Net::FTPwithCat;

    @ISA = qw(Net::FTP);

    sub new
    {
        my $pkg = shift;
        my $self = $pkg->SUPER::new(@_);
        bless $self,$pkg;
    }

    sub cat
    {
     my($ftp,$remote,$where) = @_;

     my($len,$buf,$resp,$data);
     croak("Bad remote filename '$remote'\n")
            if $remote =~ /[\r\n]/s;

     ${*$ftp}{'net_ftp_rest'} = $where if defined $where;
      my $rest = ${*$ftp}{'net_ftp_rest'};

     delete ${*$ftp}{'net_ftp_port'};
     delete ${*$ftp}{'net_ftp_pasv'};

     $data = $ftp->retr($remote) or
            return undef;
     $buf = '';
     my($count,$hashh,$hashb,$ref) = (0);
     ($hashh,$hashb) = @$ref
       if($ref = ${*$ftp}{'net_ftp_hash'});
     my $blksize = ${*$ftp}{'net_ftp_blksize'};
     local $\; # Just in case
     while(1)
      {
       last unless $len = $data->read($buf,$blksize);

       if (trEBCDIC && $ftp->type ne 'I')
        {
         $buf = $ftp->toebcdic($buf);
         $len = length($buf);
        }

       if($hashh) {
        $count += $len;
        print $hashh "#" x (int($count / $hashb));
        $count %= $hashb;
       }
       print $buf;
      }

     print $hashh "\n" if $hashh;

     unless ($data->close()) # implied $ftp->response
      {
       carp "Unable to close datastream";
       return undef;
      }
    }

---
Shinji KONO @ Information Engineering, University of the Ryukyus
河野真治 @ 琉球大学工学部情報工学科