トップ> perl scripts> Perl Net::ftpで単純なFTP送信
Perl Net::ftpで単純なFTP送信
Perl Net::ftpでFTPサーバへ送信する
CPAN Manual
Code
へたくそなプログラムはご容赦を・・・。
%FTP=(
'ftp.ugougo.com'=> { host => 'ftp.ugougo.com',
user => 'account',
pass => 'password',
remote => '/public_html/html',
local => '../html',
pattern => '.htm$|.html$|.css$' } );
sub ftp{
my ( $which ) = @_;
my $host = $FTP{$which}{'host'} ;
my $user = $FTP{$which}{'user'} ;
my $pass = $FTP{$which}{'pass'} ;
my $remote = $FTP{$which}{'remote'} ;
my $local = $FTP{$which}{'local'} ;
my $pattern= $FTP{$which}{'pattern'} ;
if( !opendir( DIR, $local ) ){
return 'cannot open folder: ' . $local;
}
my @files = readdir( DIR );
closedir( DIR );
$ftp = Net::FTP->new( $host, Debug => 0)
or return "Cannot connect to some.host.name: $@";
$ftp->login( $user, $pass ) or return "Cannot login ", $ftp->message;
$ftp->binary( ) or return "Cannot mode bin ", $ftp->message;
foreach my $file (@files) {
if( -f "$local/$file" && $file =~ /$pattern/ ){
$ftp->put( "$local/$file", "$remote/$file" )
or return "Cannot put ", $ftp->message;
}
}
$ftp->quit;
return '';
}
カテゴリ内の記事
- 404ファイルが存在しないを自前で作る(2005/09/14)
- .htaccessでSSIを有効に(2005/09/24)
- HTMLのタグ変換、改行変換などのCGI/PERLスクリプト(2005/10/01)
- メール送信のcgi/perlスクリプト関数(2005/10/01)
- 配列の個数(2005/10/05)
- FTPコマンドで自動ログイン(2006/04/11)
- お気に入り追加(2006/05/02)
- 続)メールのヘッダをMIMEエンコード(2006/05/08)
- Perl Net::ftpで単純なFTP送信(2006/05/12)
- Perlでsocketのタイムアウト(2006/07/12)
