<?php
/* $id: ftp.php,v 2.2 2002/03/12 23:21:28 pauls exp $ */
/* this software came from http://inebria.com/ */
/* copyright (c) 2000
paul southworth.all rights rerved.
redistribution and u in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following discl沆瀣一气的意思aimer in the
documentation and/or other materials provided with the distribution.
3. the name of the author may not be ud to endor or promote
products derived from this software without specific prior
written permission.
this software is provided by the author “as is” and any express
or implied warranties, including, but not limited to, the implied
warranties of merchantability and fitness for a particular purpo
are disclaimed.in no event shall the author be liable for any
direct, indirect, incidental, special, exemplary, or conquential
damages (including, but not limited to, procurement of substitute
goods or rvices; loss of u, data, or profits; or business
interruption) however caud and on any theory of liability,
whether in contract, strict liability, or tort (including negligence
or otherwi) arising in any way out of the u of this software,
even if advid of the possibility of such damage. */
/* configuration options */
$phpftp_host=”localhost”;
$phpftp_version=”2.2″;
/* comment this out if you don’t want the version footer */
$show_version_footer=1;
/* how large a file will you accept?you may also need to edit your
php.ini file and change upload_max_filesize appropriately */
$max_file_size=”1000000″;
/* the temporary directory $phpftp_tmpdir must exist and be writable
by your web rver.
hint:mkdir /var/tmp/xfers && chmod 1777 /var/tmp/xfers */
$phpftp_tmpdir=”/var/tmp/xfers”;
/* $u_mime_lookup
turning this on creates a dependency upon the
http://www.inebria.com/mime_lookup/ mime type lookup library.
tting this variable to “1” enables it.“0” disables.
if you turn it on, put the mime_lookup.php file in the same directory
as ftp.php and uncomment the ‘include(“mime_lookup.php”);’ statement. */
$u_mime_lookup=”0″;
/* include(“mime_lookup.php”); */
/* we enclo the top and bottom in functions becau sometimes
we might not nd them (ie, in a file-download situation) */
function phpftp_top() {
global $phpftp_version;
?>
<!– function phpftp_top –>
<html>
<head>
<title>php ftp client <?php echo $phpftp_version; ?></title>
</head>
<body bgcolor=”#ffffff”>
<?php
}
function phpftp_bottom() {
global $phpftp_version;
global $show_version_footer;
?>
<!– function phpftp_bottom –>
<?php
if (ist($show_version_footer)) {
?>
<p><font size=-2>this is <a href=”http://inebria.com/phpftp/”>php ftp</a>
version <?php echo $phpftp_version; ?></font></p>
<?php
}
?>
</body>
</html>
<?php
}
/* this is the form ud for initially collecting urname/passwd */
function phpftp_login() {
phpftp_top();
?>
<!– function phpftp_login –>
<p>
<form action=”ftp.php” method=post>
<p><table border=0>
<tr><td>
login:
</td><td>
<input name=”phpftp_ur” type=”text”>
</td></tr>
<tr><td>
password:
</td><td>
<input name=”phpftp_passwd” type=”password”>
</td></tr>
<tr><td>
directory:
</td><td>
<input name=”phpftp_dir” type=”text”>
</td></tr>
</table>
</p><p>
<input type=”hidden” name=”function” value=”dir”>
<input type=”submit” value=”connect”>
</p>
</form>
<p>
<?php
phpftp_bottom();
}
/* this function does not return true/fal – it returns the value of
$ftp, the current ftp stream. */
function phpftp_connect($phpftp_ur,$phpftp_passwd) {
global $phpftp_host;
$ftp = ftp_connect($phpftp_host);
if ($ftp) {
if (ftp_login($ftp,$phpftp_ur,urldecode($phpftp_passwd))) {
return $ftp;
}
}
}
function phpftp_list($phpftp_ur,$phpftp_passwd,$phpftp_dir) {
global $phpftp_host;
phpftp_top();
?>
<!– function phpftp_list –>
<?php
$ftp = @phpftp_connect($phpftp_ur,$phpftp_passwd);
if (!$ftp) {
?>
<strong>ftp login failed!</strong>
<a href=”ftp.php”>start over?</a>
<?php
phpftp_bottom();
} el {
if (!$phpftp_dir) {
$phpftp_dir=ftp_pwd($ftp);
}
if (!@ftp_chdir($ftp,$phpftp_dir)) {
?>
<font color=”#ff0000″><strong>can’t enter that directory!</strong></font><p><p>
<?php
$phpftp_dir=ftp_pwd($ftp);
}
echo “<strong>current host:</strong> ” . $phpftp_host . “<br>\n”;
echo “<strong>current directory:</strong> ” . $phpftp_dir . “<br>\n”;
if ($phpftp_dir == “/”) {
$phpftp_dir=””;
}
if ($contents = ftp_rawlist($ftp,””)) {
$d_i=0;
$f_i=0;
$l_i=0;
$i=0;
while ($contents[$i]) {
$item[] = split(“[ ]+”,$contents[$i],9);
$item_type=substr($item[$i][0],0,1);
if ($item_type == “d”) {
/* it’s a directory */
$nlist_dirs[$d_i]=$item[$i][8];
$d_i++;
} elif ($item_type == “l”) {
/* it’s a symlink */
$nlist_links[$l_i]=$item[$i][8];
$l_i++;
} elif ($item_type == “-“) {
/* it’s a file */
$nlist_files[$f_i]=$item[$i][8];
$nlist_filesize[$f_i]=$item[$i][4];
$f_i++;
} elif ($item_type == “+”) {
/* it’s something on an anonftp rver */
$eplf=split(“,”,implode(” “,$item[$i]),5);
if ($eplf[2] == “r”) {
/* it’s a file */
$nlist_files[$f_i]=trim($eplf[4]);
$nlist_filesize[$f_i]=substr($eplf[3],1);
$f_i++;
} elif ($eplf[2] == “/”) {
/* it’s a directory */
$nlist_dirs[$d_i]=trim($eplf[3]);
$d_i++;
}
} /* ignore all others */
$i++;
}
?>
<table border=0 cellspacing=20>
<?php
if (count($nlist_dirs)>0) {
?>
<tr><td align=left valign=top>
<strong>directories</strong><br>
<form action=”ftp.php” method=post>
<input type=”hidden” name=”function” value=”cd”>
<input type=”hidden” name=”phpftp_ur” value=”<?php echo $phpftp_ur; ?>”>
<input type=”hidden” name=”phpftp_passwd” value=”<?php echo $phpftp_passwd; ?>”>
<input type=”hidden” name=”phpftp_dir” value=”<?php echo $phpftp_dir; ?>”>
<lect name=”lect_directory” size=”10″ width=”100″>
<?php
for ($i=0; $i < count($nlist_dirs); $i++) {
echo 感恩节的由来简介“<option value=\”” . $nlist_dirs[$i] . “\”>” . $nlist_dirs[$i] . “</option>\n”;
}
?>
</物管法lect><br>
<input type=”submit” value=”enter directory”>
</form>
</td>
<?php
}
if (count($nlist_files)>0) {
?>
<td align=left valign=top>
<strong>files</strong><br>
<form action=”ftp.php” method=post>
<input type=”hidden” name=”function” value=”get”>
<input type=”hidden” name=”phpftp_ur” value=”<?php echo $phpftp_ur; ?>”>
<input type=”hidden” name=”phpftp_passwd” value=”<?php echo $phpftp_passwd; ?>”>
<input type=”hidden” name=”phpftp_dir” value=”<?php echo $phpftp_dir; ?>”>
<lect name=”lect_file” size=”10″>
<?php
for ($i=0; $i < count($nlist_files); $i++) {
echo “<option value=\”” . $nlist_files[$i] . “\”>” . $nlist_files[$i] .”($nlist_filesize[$i] bytes)”. “</option>\n”;
}
?>
</lect><br>
<input type=”submit” value=”download file”>
</form>
</td></tr>
<?php
}
} el {
?>
<p><font color=”#ff0000″><strong>directory empty or not readable</strong></font><p>
<?php
}
?>
</table>
<p>
<form action=”ftp.php” method=pacrossost>
<?php
$cdup=dirname($phpftp_dir);
if ($cdup == “”) {
$cdup=”/”;
}
?>
<input type=”hidden” name=”function” value=”dir”>
<input type=”hidden” name=”phpftp_ur” value=”<?php echo $phpftp_ur; ?>”>
<input type=”hidden” name=”phpftp_passwd” value=”<?php echo $phpftp_passwd; ?>”>
<input type=”hidden” name=”phpftp_dir” value=”<?php echo $cdup; ?>”>
<input type=”submit” value=”go up one directory”>
</form>
<p>
<form enctype=”multipart/form-data” action=”ftp.php” method=post>
<input type=”hidden” name=”max_file_size” value=”<?php echo $max_file_size ?>”>
<input type=”hidden” name=”phpftp_ur” value=”<?php echo $phpftp_ur; ?>”>
<input type=”hidden” name=”phpftp_passwd” value=”<?php echo $phpftp_passwd; ?>”>
<input type=”hidden” name=”phpftp_dir” value=”<?php echo $phpftp_dir; ?>”>
<input type=”hidden” name=”function” value=”put”>
<input type=”submit” value=”upload this:”>
<input name=”urfile” type=”file”>
</form>
<p>
<form action=”ftp.php” method=post>
<input type=”hidden” name=”function” value=”mkdir”>
<input type=”hidden” name=”phpftp_ur” value=”<?php echo $phpftp_ur; ?>”>
<input type=”hidden” name=”phpftp_passwd” value=”<?php echo $phpftp_passwd; ?>”>
<input type=”hidden” name=”phpftp_dir” value=”<?php echo $phpftp_dir; ?>”>
<input type=”submit” value=”make subdirectory:”>
<input name=”new_dir” type=”text”>
<?php
ftp_quit($ftp);
phpftp_bottom();
}
}
function phpftp_cd($phpftp_ur,$phpftp_passwd,$phpftp_dir,$lect_directory) {
?>
<!– function phpftp_cd –>
<?php
$new_directory=$phpftp_dir . “/” . $lect_directory;
phpftp_list($phpftp_ur,$phpftp_passwd,$new_directory);
}
function phpftp_mkdir($phpftp_ur,$phpftp_passwd,$phpftp_dir,$new_dir) {
?>
<!– function phpftp_mkdir –>
<?php
$ftp = @phpftp_connect($phpftp_ur,$phpftp_passwd);
if ($phpftp_dir == “”) {
$phpftp_dir=”/”;
}
if (!$ftp) {
@ftp_quit($ftp);
phpftp_top();
?>
<font color=”#ff0000″><strong>ftp login failed!</strong></font><p><p>
<a href=”ftp.php”>start over?</a>
<?php
phpftp_bottom();
} el {
$dir_path = $phpftp_dir . “/” . $new_dir;
@ftp_mkdir($ftp,$dir_path);
@ftp_quit($ftp);
phpftp_list($phpftp_ur,$phpftp_passwd,$phpftp_dir);
}
};
function phpftp_get($phpftp_ur,$phpftp_passwd,$phpftp_dir,$lect_file) {
$ftp = @phpftp_connect($phpftp_ur,$phpftp_passwd);
if ($phpftp_dir == “”) {
$phpftp_dir=”/”;
}
if ((!$ftp) || (!@ftp_chdir($ftp,$phpftp_dir))) {
@ftp_quit($ftp);
phpftp_top();
?>
<font color=”#ff0000″><strong>ftp login failed!</strong></font><p><p>
<a href=”ftp.php”>start over?</a>
<?php
phpftp_bottom();
} el {
srand((double)microtime()*1000000);
$randval = rand();
$tmpfile=$phpftp_tmpdir . “/” . $lect_file . “.” . $randval;
if (!ftp_get($ftp,$tmpfile,$lect_file,ftp_binary)) {
ftp_quit($ftp);
phpftp_top();
?>
<font color=”#ff0000″><strong>ftp get failed!</strong></font><p><p>
<a href=”ftp.php”>start over?</a>
<?php
phpftp_bottom();
} el {
ftp_quit($ftp);
global $u_mime_lookup;
if ($u_mi离婚上诉状me_lookup == “1”) {
$file_mime_type=mime_lookup(substr(strrchr($lect_file,”.”),1));
}
if (!$file_mime_type) {
$file_mime_type=”application/octet-stream”;
}
header(“content-type: ” . $file_mime_type);
header(“content-disposition: attachment; filename=” . $lect_file);
readfile($tmpfile);
}
@unlink($tmpfile);
}
}
function phpftp_put($phpftp_ur,$phpftp_passwd,$phpftp_dir,$urfile,$urfile_name) {
srand((double)microtime()*1000000);
$randval = rand();
$tmpfile=$phpftp_tmpdir . “/” . $urfile_name . “.” . $randval;
if (!@move_uploaded_file($urfile,$tmpfile)) {
phpftp_top();
?>
<font color=”#ff0000″><strong>upload failed!can’t create temp file?</strong></font>
<p><p>
<a href=”ftp.php”>start over?</a>
<?php
phpftp_bottom();
} el {
if (!$ftp = @phpftp_connect($phpftp_ur,$phpftp_passwd)) {
unlink($tmpfile);
phpftp_top();
?>
<font color=”#ff0000″><strong>ftp login failed!</strong></font><p><p>
<a href=”ftp.php”>start over?</a>
<?php
phpftp_bottom();
} el {
ftp_chdir($ftp,$phpftp_dir);
ftp_put($ftp,$urfile_name,$tmpfile,ftp_binary);
ftp_quit($ftp);
unlink($tmpfile);
phpftp_list($phpftp_ur,$phpftp_passwd,$phpftp_dir);
}
}
}
switch($function) {
ca “dir”;
phpftp_list($phpftp_ur,$phpftp_passwd,$phpftp_dir);
break;
ca “cd”;
phpftp_cd($phpftp_ur,$phpftp_passwd,$phpftp_dir,$lect_directory);
break;
ca “get”;
phpftp_get($phpftp_ur,$phpftp_passwd,$phpftp_dir,$lect_file);
break;
ca “put”;
phpftp_put($phpftp_ur,$phpftp_passwd,$phpftp_dir,$urfile,$urfile_name);
break;
ca “mkdir”;
phpftp_mkdir($phpftp_ur,$phpftp_passwd,$phpftp_dir,$new_dir);
break;
ca “”;
phpftp_login();
break;
}
?>
本文发布于:2023-04-06 06:58:21,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/d0b3dee36c00bd1f9d213fdf3ef75ee5.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:web方式ftp.doc
本文 PDF 下载地址:web方式ftp.pdf
留言与评论(共有 0 条评论) |