webftp php,web方式ftp

web方式ftp

更新时间:2006年10月09日 00:00:00   作者:

/* $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 reserved.

Redistribution and use 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 disclaimer in the

documentation and/or other materials provided with the distribution.

3. The name of the author may not be used to endorse 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 PURPOSE

ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY

DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL

DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE

GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS

INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,

WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE

OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,

EVEN IF ADVISED 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 server.

Hint:  mkdir /var/tmp/xfers && chmod 1777 /var/tmp/xfers */

$phpftp_tmpdir="/var/tmp/xfers";

/* $use_mime_lookup

Turning this on creates a dependency upon the

http://www.inebria.com/mime_lookup/ MIME type lookup library.

Setting 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. */

$use_mime_lookup="0";

/* include("mime_lookup.php"); */

/* We enclose the top and bottom in functions because sometimes

we might not send them (ie, in a file-download situation) */

function phpftp_top() {

global $phpftp_version;

?>

PHP FTP Client <?php echo $phpftp_version; ?>

}

function phpftp_bottom() {

global $phpftp_version;

global $show_version_footer;

?>

if (isset($show_version_footer)) {

?>

This is PHP FTP

version <?php echo $phpftp_version; ?>

}

?>

}

/* This is the form used for initially collecting username/passwd */

function phpftp_login() {

phpftp_top();

?>

Login:

Password:

Directory:

phpftp_bottom();

}

/* This function does not return TRUE/FALSE - it returns the value of

$ftp, the current FTP stream. */

function phpftp_connect($phpftp_user,$phpftp_passwd) {

global $phpftp_host;

$ftp = ftp_connect($phpftp_host);

if ($ftp) {

if (ftp_login($ftp,$phpftp_user,urldecode($phpftp_passwd))) {

return $ftp;

}

}

}

function phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir) {

global $phpftp_host;

phpftp_top();

?>

$ftp = @phpftp_connect($phpftp_user,$phpftp_passwd);

if (!$ftp) {

?>

FTP login failed!

Start over?

phpftp_bottom();

} else {

if (!$phpftp_dir) {

$phpftp_dir=ftp_pwd($ftp);

}

if (!@ftp_chdir($ftp,$phpftp_dir)) {

?>

Can't enter that directory!

$phpftp_dir=ftp_pwd($ftp);

}

echo "Current host: " . $phpftp_host . "
\n";

echo "Current directory: " . $phpftp_dir . "
\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++;

} elseif ($item_type == "l") {

/* it's a symlink */

$nlist_links[$l_i]=$item[$i][8];

$l_i++;

} elseif ($item_type == "-") {

/* it's a file */

$nlist_files[$f_i]=$item[$i][8];

$nlist_filesize[$f_i]=$item[$i][4];

$f_i++;

} elseif ($item_type == "+") {

/* it's something on an anonftp server */

$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++;

} elseif ($eplf[2] == "/") {

/* it's a directory */

$nlist_dirs[$d_i]=trim($eplf[3]);

$d_i++;

}

} /* ignore all others */

$i++;

}

?>

if (count($nlist_dirs)>0) {

?>

Directories

for ($i=0; $i < count($nlist_dirs); $i++) {

echo "" . $nlist_dirs[$i] . "\n";

}

?>

}

if (count($nlist_files)>0) {

?>

Files

for ($i=0; $i < count($nlist_files); $i++) {

echo "" . $nlist_files[$i] ."  ($nlist_filesize[$i] bytes)". "\n";

}

?>

}

} else {

?>

Directory empty or not readable

}

?>

$cdup=dirname($phpftp_dir);

if ($cdup == "") {

$cdup="/";

}

?>

ftp_quit($ftp);

phpftp_bottom();

}

}

function phpftp_cd($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_directory) {

?>

$new_directory=$phpftp_dir . "/" . $select_directory;

phpftp_list($phpftp_user,$phpftp_passwd,$new_directory);

}

function phpftp_mkdir($phpftp_user,$phpftp_passwd,$phpftp_dir,$new_dir) {

?>

$ftp = @phpftp_connect($phpftp_user,$phpftp_passwd);

if ($phpftp_dir == "") {

$phpftp_dir="/";

}

if (!$ftp) {

@ftp_quit($ftp);

phpftp_top();

?>

FTP login failed!

Start over?

phpftp_bottom();

} else {

$dir_path = $phpftp_dir . "/" . $new_dir;

@ftp_mkdir($ftp,$dir_path);

@ftp_quit($ftp);

phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir);

}

};

function phpftp_get($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_file) {

$ftp = @phpftp_connect($phpftp_user,$phpftp_passwd);

if ($phpftp_dir == "") {

$phpftp_dir="/";

}

if ((!$ftp) || (!@ftp_chdir($ftp,$phpftp_dir))) {

@ftp_quit($ftp);

phpftp_top();

?>

FTP login failed!

Start over?

phpftp_bottom();

} else {

srand((double)microtime()*1000000);

$randval = rand();

$tmpfile=$phpftp_tmpdir . "/" . $select_file . "." . $randval;

if (!ftp_get($ftp,$tmpfile,$select_file,FTP_BINARY)) {

ftp_quit($ftp);

phpftp_top();

?>

FTP get failed!

Start over?

phpftp_bottom();

} else {

ftp_quit($ftp);

global $use_mime_lookup;

if ($use_mime_lookup == "1") {

$file_mime_type=mime_lookup(substr(strrchr($select_file,"."),1));

}

if (!$file_mime_type) {

$file_mime_type="application/octet-stream";

}

header("Content-Type: " . $file_mime_type);

header("Content-Disposition: attachment; filename=" . $select_file);

readfile($tmpfile);

}

@unlink($tmpfile);

}

}

function phpftp_put($phpftp_user,$phpftp_passwd,$phpftp_dir,$userfile,$userfile_name) {

srand((double)microtime()*1000000);

$randval = rand();

$tmpfile=$phpftp_tmpdir . "/" . $userfile_name . "." . $randval;

if (!@move_uploaded_file($userfile,$tmpfile)) {

phpftp_top();

?>

Upload failed!  Can't create temp file?

Start over?

phpftp_bottom();

} else {

if (!$ftp = @phpftp_connect($phpftp_user,$phpftp_passwd)) {

unlink($tmpfile);

phpftp_top();

?>

FTP login failed!

Start over?

phpftp_bottom();

} else {

ftp_chdir($ftp,$phpftp_dir);

ftp_put($ftp,$userfile_name,$tmpfile,FTP_BINARY);

ftp_quit($ftp);

unlink($tmpfile);

phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir);

}

}

}

switch($function) {

case "dir";

phpftp_list($phpftp_user,$phpftp_passwd,$phpftp_dir);

break;

case "cd";

phpftp_cd($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_directory);

break;

case "get";

phpftp_get($phpftp_user,$phpftp_passwd,$phpftp_dir,$select_file);

break;

case "put";

phpftp_put($phpftp_user,$phpftp_passwd,$phpftp_dir,$userfile,$userfile_name);

break;

case "mkdir";

phpftp_mkdir($phpftp_user,$phpftp_passwd,$phpftp_dir,$new_dir);

break;

case "";

phpftp_login();

break;

}

?>

相关文章

1a1b05c64693fbf380aa1344a7812747.png

PHP中动态HTML的输出技术...2006-10-10

4f55910a645b073bc4fc65dc10dc14bd.png

今天小编就为大家分享一篇关于PHP PDOStatement::debugDumpParams讲解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧2019-01-01

0ea3c7666119d5615e582f823fb3fad6.png

来自PHP.NET的入门教程...2006-10-10

4f96a78db829b1556ff16de21e013c7a.png

实现分十页分向前十页向后十页的处理...2006-10-10

8cc1031babc6aff2319f1c6af8544aa0.png

PHP脚本数据库功能详解(中)...2006-10-10

0c932a99bb7b6f23c937db507070cc7b.png

PHP.MVC的模板标签系统(五)...2006-09-09

cca732bf65a93ed2ec0ac80c638460fe.png

php入门学习知识点八 PHP中for循环基本应用之九九乘法口绝表,需要的朋友可以参考下。主要是掌握for命令的灵活运用。2011-07-07

2d9f31f2af7b675a3d153d2b7f1035a7.png

针对初学建站的同学,本文主要介绍用PHP编程语言建设网站的步骤和流程,希望对你有帮助,一起来看。2015-09-09

b452cee8ec5cd9e58ab98eba17281e59.png

PHP:风雨欲来 路在何方?...2006-10-10

f4838ec7e2d4da28e0b57d4e852dadd4.png

php中处理模拟rewrite 效果...2006-12-12

最新评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值