首页 > 解决方案 > STFP 连接和下载混淆

问题描述

一直试图通过 PHP 和 SFTP 将 Filezilla 和我的网站连接在一起被证明是乏味的。

你如何连接STFP,网上的信息大部分都很简短,我已经下载了SSH2.php文件并使用了文件中包含的代码(测试文件),但它不起作用。该页面未加载,由于使用了我怀疑的 SSH2 功能而显示错误消息。

联系

// Connect to FileZilla
include("../model/connection.php");
$con = new SFTPobj();
$connect =  $con->serverConnection();

测试文件:

Class SFTPobj{
function serverConnection()
{
    include('../controller/SSH2.php');
    $server = "xx";
    $user = "xx";
    $pass = "xx";  
    $ssh = new Net_SSH2($server);
        if (!$ssh->login( $user, $pass)) {
        exit('Login Failed');
    }
    echo $ssh->exec('pwd');
    echo $ssh->exec('ls -la');
}

}

测试文件- * 代码(大部分无关):

    <?php
    // Connect to database
    include("../model/connection.php");
    $con = new SFTPobj();
    $connect =  $con->serverConnection();

    if(isset($_POST['submit']))
        {
        $file = $_FILES['file'];
            print_r($file);

        $fileName=$_FILES['file']['name'];
        $fileTmpName=$_FILES['file']['tmp_name'];
        $fileSize=$_FILES['file']['size'];
        $fileError=$_FILES['file']['error'];
        $fileType=$_FILES['file']['type'];

        #only allow images
        $fileExt = explode('.', $fileName);
        $fileActualExt = strtolower(end($fileExt));

        #Image types
        $allowed = array('jpg','jpeg', 'png');

        #Check file type
        if(in_array($fileActualExt,$allowed))
        {
            if($fileError === 0)
            {
                if($fileSize < 500000) #500KB
                {
                    $fileNameNew = uniqid('', true).".".$fileActualExt; #Random Number Generate
                    $fileDestination = '../view/pictures/week1'.$fileNameNew;
                    move_uploaded_file($fileTmpName,$fileDestination);
                    header("Location:../view/test.php?uploadSuccess");
                }else{
                    echo "Your file is too big";
                }
            }else{
                echo "There was an error uploading your file";
            }
        }else{
            echo "You can not upload files of this type";
        }



    }

?>

标签: phpphpseclib

解决方案


从您的文件中:

include('../controller/SSH2.php');

在 zip 文件下载中,SSH2.php 位于 Net/ 目录中。还有一个 Crypt/ 目录和一个 Math/ 目录。这两者都是必需的,并且相对路径也需要正确。

您已将 SSH2.php 从 Net/ 目录中删除的事实使我认为您可能没有其他必需的文件。即使你这样做,我也怀疑它们是否处于正确的相对位置。

此外,由于您似乎使用的是 1.0 分支,您可能需要设置 include_path 以使其正常工作,具体取决于您放置目录的位置:

<?php
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');

include('Net/SSH2.php');
?>

真的,我只是建议不要选择您认为需要的文件。只需获取整个 phpseclib zip 文件并将其转储到 phpseclib 文件中。


推荐阅读