#!/usr/bin/perl # 2008/07/07 ver.0.0.0.0 ## 設定 # パスワード 「perl -e "print crypt('パスワード', 'hu');"」で表示された物を設定してください。勿論、「パスワード」の部分は変更してください(英数字のみ使用可)。 $password = 'aaaaaaaaaaaaaaaaaa'; # 指定秒数以上起動している場合強制終了 eval{alarm(5*60)};$SIG{'ALRM'}='timeout'; sub timeout{ print '*** TimeOut ***'; exit; } sub error{ print 'Error : ' . $_; exit; } print <<'END'; Content-Type: text/html; charset=Shift_JIS Pragma: no-cache Cache-Control: no-store

FTPサーバがMDTMコマンドに対応しておらず、FTPでファイルを転送すると、タイムスタンプが転送した時間になってしまう場合に使用するスクリプト

説明

手順

  1. localhost で実行して、ftp_timestamp.txt を作る
  2. ファイルを全てアップロード
  3. サーバーで実行して、現在になってしまっているタイムスタンプを本来の物に修正

ftp_timestamp.txt が END if ($ENV{'REQUEST_METHOD'} =~ m/post/i && length($password)) { read(STDIN, $_POST, $ENV{'CONTENT_LENGTH'}); if ($password eq crypt(($_POST =~ m/(?:^|&)password=([^&]+)/)[0], 'hu')) { if (-f 'ftp_timestamp.txt' && !-z 'ftp_timestamp.txt') { print 'あります!

適用開始

';
			open(F, 'ftp_timestamp.txt') || &error('open ftp_timestamp.txt');
			while ($tmp = ) {
				($file, $atime, $mtime) = split('	', $tmp);
				if (utime($atime, $mtime, $file)) {
					print "OK	$file	$atime	$mtime";
				} else {
					print "NG	$file	$atime	$mtime";
				}
			}
			close(F);
			unlink('ftp_timestamp.txt');
			print 'ftp_timestamp.txt を削除しました。';
		} else {
			print 'ありません。

記録開始

';
			open(F, '>ftp_timestamp.txt') || &error('open ftp_timestamp.txt');
			$nowdir = './';
			while ($nowdir) {
				opendir(DIR, $nowdir) || &error("opendir $nowdir");
				while ($tmp = readdir(DIR)) {
					next if $tmp =~ m/^\.\.?$/;
					if (-d "$nowdir$tmp") {
						@dir[$i] = "$nowdir$tmp/";
						++$i;
					}
					$atime = (stat("$nowdir$tmp"))[8];
					$mtime = (stat("$nowdir$tmp"))[9];
					print "$nowdir$tmp	$atime	$mtime\n";
					print F "$nowdir$tmp	$atime	$mtime\n";
				}
				$nowdir = @dir[$ii];
				++$ii;
			}
			close(F);
		}
		closedir(DIR);
		
		print '
正常終了'; exit; } } # GET or PassWordError if (-f 'ftp_timestamp.txt' && !-z 'ftp_timestamp.txt') { @stat = stat('ftp_timestamp.txt'); ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($stat[9]); $mtime = sprintf("%04d年%02d月%02d日 %02d:%02d:%02d", $year + 1900, $mon +1, $mday, $hour, $min, $sec); print ' あります! (' .$mtime. '更新)'; } else { print ' ありません。'; } if (!length($password)) { print '

ERROR : $password が設定されていません。

'; } elsif ($ENV{'REQUEST_METHOD'} =~ m/post/i) { print '

ERROR : パスワードが一致しません。

'; } print '
' . 'PassWord : ' . ' ' . '
';