ftp
#!/usr/local/bin/perl
#################################################################
# I found this script at http://www.terminalp.com
# it was written by a guy named Jeff who sold the domain and
# disappeared. I deleted the original header to save space
# so I am distributing this as is. If Jeff sees this, please
# email me at dreun@eskimo.com!! Thanks, Ron Hagerman
#################################################################
$| = 1;
#设定$OUTPUT_AUTOFLUSH为1,也就是使STDOUT不对输出进行缓冲,而是直接输出。
chop $SAVE_DIRECTORY if ($SAVE_DIRECTORY =~ //$/);
#若保存目的地址以"/"结尾 则将其删除
use CGI qw(:standard);
#使用CGI模块
$query = new CGI;
#生成一个新的CGI对象
#当指定的保存目的目录名不存在或不可写或不是目录时 输出错误信息
if ( (!(-e $SAVE_DIRECTORY)) ||
(!(-W $SAVE_DIRECTORY)) ||
(!(-d $SAVE_DIRECTORY)) ) {
print header;
#输出http信息头
print <<__END_OF_HTML_CODE__;
#这里的<<__END_OF_HTML_CODE__指示print语句输出文件后面的内容 直到遇到__END_OF_HTML_CODE__ 你可以使用别的符号来替代__END_OF_HTML_CODE__
<HTML>
<HEAD>
<TITLE>Error: Bad Directory</TITLE>
</HEAD>
<BODY BGcolor="#FFFFFF">
<H1>Bad Directory</H1>
<>
The directory you specified:
<BR>
<BLOCKQUOTE>
<TT>$SAVE_DIRECTORY = "<B>$SAVE_DIRECTORY</B>";</TT>
</BLOCKQUOTE>
<BR>
is invalid. This problem is caused by one of the three following reasons:
<OL>
<LI>The directory doesn“t exist. Make sure that this directory is a complete path name, not
a URL or something similar. It should look similar to <TT>/home/username/public_html/uploads</TT>
<>
<LI>The directory isn“t writable. Make sure that this directory is writable by all users. At
your UNIX command prompt, type <TT>chmod 777 $SAVE_DIRECTORY</TT>
<>
<LI>The directory you specified isn“t really a directory. Make sure that this is indeed a directory
and not a file.
</OL>
</BODY>
</HTML>
__END_OF_HTML_CODE__
exit;
}
foreach $key (sort {$a <=> $b} $query->param()) {
#对html form中的各个元素的名字进行排序 然后对每个名字进行如下操作
next if ($key =~ /^s*$/);
#若名字为空 则进行下一次循环
next if ($query->param($key) =~ /^s*$/);
#若名字对应的值为空 则进行下一次循环
next if ($key !~ /^file-to-upload-(d+)$/);
#若名字不为file-to-upload-(数字)的形式 则进行下一次循环
$Number = $1;
<HTML>
<HEAD>
<TITLE>Error: Filename Problem</TITLE>
</HEAD>
<BODY BGcolor="#FFFFFF">
<H1>Filename Problem</H1>
<>
You attempted to upload a file that isn“t properly formatted. The system administrator
has decided that you can“t upload files that begin with the word “<B>index</B>“. Please
rename the file on your computer, and try uploading it again.
<>
</BODY>
</HTML>
__END_OF_HTML_CODE__
exit;
}
#end of decide whether the file can be index.* style
} else {
#当取得的文件名为空 则输出错误信息
$FILENAME_IN_QUESTION = $query->param($key);
#取得该文件路径到变量$FILENAME_IN_QUESTION中 然后输出错误信息
print header;
print <<__END_OF_HTML_CODE__;
<HTML>
<HEAD>
<TITLE>Error: Filename Problem</TITLE>
</HEAD>
<BODY BGcolor="#FFFFFF">
<H1>Filename Problem</H1>
<>
You attempted to upload a file that isn“t properly formatted. The file in question
is <TT><B>$FILENAME_IN_QUESTION</B></TT> Please rename the file on your computer, and
attempt to upload it again. Files may not have forward or backward slashes in their
names. Also, they may not be prefixed with one (or more) periods.
<>
</BODY>
</HTML>
__END_OF_HTML_CODE__
exit;
}
if (!open(OUTFILE, ">$SAVE_DIRECTORY/$Filename")) {
#以写入的方式在上载目录下创建与上载文件同名的文件 若打开错误则输出错误信息
print "Content-type: text/plainnn";
print "-------------------------n";
print "Error:n";
print "-------------------------n";
print "File: $SAVE_DIRECTORY/$Filenamen";
print "-------------------------n";
print "There was an error opening the Output Filen";
print "for Writing.nn";
print "Make sure that the directory:n";
print "$SAVE_DIRECTORYn";
print "has been chmodded with the permissions “777“.nn";
print "Also, make sure that if your attemptingn";
print "to overwrite an existing file, that then";
print "existing file is chmodded “666“ or better.nn";
print "The Error message below should help you diagnosen";
print "the problem.nn";
print "Error: $!n";
exit;
}
<HTML>
<HEAD>
<TITLE>Error: Limit Reached</TITLE>
</HEAD>
<BODY BGcolor="#FFFFFF">
<H1>Limit Reached</H1>
<>
You have reached your upload limit. You attempted to upload <B>$FILES_UPLOADED</B> files, totalling
<B>$TOTAL_BYTES</B>. This exceeds the maximum limit of <B>$MAXIMUM_UPLOAD</B> bytes, set by the system
administrator. <B>None</B> of your files were successfully saved. Please try again.
<>