热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

web方式ftp,建议加入精华区,嘿嘿

?php/*$Id:ftp.php,v2.22002/03/1223:21:28paulsExp$*//*Thissoftwarecamefromhttp://inebria.com/*//*Copyright(c)2000PaulSouthworth.Allrightsreserved.Redistributiona
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 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;
?>






}

function phpftp_bottom() {
    global $phpftp_version;
    global $show_version_footer;
?>

if (isset($show_version_footer)) {
?>

This is PHP FTP
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) {
?>

            }

            if (count($nlist_files)>0) {
?>

            }
        } else {
?>

Directory empty or not readable


        }
?>


Directories











Files













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

?>


推荐阅读
  • LeetCode 540:有序数组中的唯一元素
    来源:力扣(LeetCode),链接:https://leetcode-cn.com/problems/single-element-in-a-sorted-array。题目要求在仅包含整数的有序数组中,找到唯一出现一次的元素,并确保算法的时间复杂度为 O(log n) 和空间复杂度为 O(1)。 ... [详细]
  • 如何在Faceu激萌中设置和使用妆容切换特效?
    本文将详细介绍如何在Faceu激萌应用中设置和使用妆容切换特效,帮助用户轻松实现创意拍摄。无论是新手还是有经验的用户,都能从中受益。 ... [详细]
  • 本文介绍如何解决在 IIS 环境下 PHP 页面无法找到的问题。主要步骤包括配置 Internet 信息服务管理器中的 ISAPI 扩展和 Active Server Pages 设置,确保 PHP 脚本能够正常运行。 ... [详细]
  • Python 异步编程:深入理解 asyncio 库(上)
    本文介绍了 Python 3.4 版本引入的标准库 asyncio,该库为异步 IO 提供了强大的支持。我们将探讨为什么需要 asyncio,以及它如何简化并发编程的复杂性,并详细介绍其核心概念和使用方法。 ... [详细]
  • 探讨一个老旧 PHP MySQL 系统中,时间戳字段不定期出现异常值的问题及其可能原因。 ... [详细]
  • 国内BI工具迎战国际巨头Tableau,稳步崛起
    尽管商业智能(BI)工具在中国的普及程度尚不及国际市场,但近年来,随着本土企业的持续创新和市场推广,国内主流BI工具正逐渐崭露头角。面对国际品牌如Tableau的强大竞争,国内BI工具通过不断优化产品和技术,赢得了越来越多用户的认可。 ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • 郑州大学在211高校中的地位与排名解析
    本文将详细解读郑州大学作为一所位于河南省的211和双一流B类高校,在全国211高校中的地位与排名,帮助高三学生更好地了解这所知名学府的实力与发展前景。 ... [详细]
  • 深入理解 Oracle 存储函数:计算员工年收入
    本文介绍如何使用 Oracle 存储函数查询特定员工的年收入。我们将详细解释存储函数的创建过程,并提供完整的代码示例。 ... [详细]
  • 优化ASM字节码操作:简化类转换与移除冗余指令
    本文探讨如何利用ASM框架进行字节码操作,以优化现有类的转换过程,简化复杂的转换逻辑,并移除不必要的加0操作。通过这些技术手段,可以显著提升代码性能和可维护性。 ... [详细]
  • 本文总结了2018年的关键成就,包括职业变动、购车、考取驾照等重要事件,并分享了读书、工作、家庭和朋友方面的感悟。同时,展望2019年,制定了健康、软实力提升和技术学习的具体目标。 ... [详细]
  • 电子元件封装库:三极管、MOS管及部分LDO(含3D模型)
    本资源汇集了常用的插件和贴片三极管、MOS管以及部分LDO的封装,涵盖TO和SOT系列。所有封装均配有高质量的3D模型,共计96种,满足日常设计需求。 ... [详细]
  • 在计算机技术的学习道路上,51CTO学院以其专业性和专注度给我留下了深刻印象。从2012年接触计算机到2014年开始系统学习网络技术和安全领域,51CTO学院始终是我信赖的学习平台。 ... [详细]
  • CSS 布局:液态三栏混合宽度布局
    本文介绍了如何使用 CSS 实现液态的三栏布局,其中各栏具有不同的宽度设置。通过调整容器和内容区域的属性,可以实现灵活且响应式的网页设计。 ... [详细]
  • 本文详细介绍了如何使用PHP检测AJAX请求,通过分析预定义服务器变量来判断请求是否来自XMLHttpRequest。此方法简单实用,适用于各种Web开发场景。 ... [详细]
author-avatar
寒空动烟雪
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有