#! /usr/local/bin/perl # ============================================================ # put-remote # ============================================================ # $DIR で指定したディレクトリ以下にあるファイルを、ftp を # 使って $site に $name,$passwd で送りつける # ============================================================ require "ftp.pl"; $site = 'localhost'; $port=21; $call='1'; $name = '********'; $passwd = '********'; $DIR = '/home/aiba/tmp/ftp'; $RDIR = '.'; &ftp'debug(1); chdir $DIR; @files = &get_filelist("."); &send_remote(@files); exit; # # $DIR 以下のファイルの一覧を入手 # sub get_filelist { local($dir) = @_; local(@ret); if(open(I,"find $dir -type f -o -type d |")) { while() { s/[ \t\r\n]*$//; next if (/\~$/); push(@ret,$_); } close(I); } return @ret; } # # remote_host にファイルを送る # sub send_remote { local(@files) = @_; if( &ftp'open($site,$port,0,1) ) { &ftp'login($name,$passwd) || die "cannot login: $!\n"; &ftp'type('I'); &ftp'cwd($RDIR); &send_files(@files); &ftp'close; } else { die "failed: $!\n"; } } # # remote_host に個々のファイルを送る # sub send_files { local(@files) = @_; local($file, $path, $fname); foreach $file ( @files ) { $file =~ /\/[^\/]*$/; $path = $`; $fname = $'; $fname =~ s/\/$//; if( -d $file ) { &ftp'mkdir($file); } else { &ftp'put($file,$file); } } }