Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正在尝试这样做,以便您可以下载。在php中使用sftp_Php_Sftp_Phpseclib - Fatal编程技术网

正在尝试这样做,以便您可以下载。在php中使用sftp

正在尝试这样做,以便您可以下载。在php中使用sftp,php,sftp,phpseclib,Php,Sftp,Phpseclib,我试图这样做,我可以下载文件,但我有一个问题,不知道如何修复它你能帮我找到错误吗 什么也没发生。帮我把这件事做好。我不知道如何解决这个问题,所以我需要所有能得到的帮助 <?php require("configuration.php"); require("include.php"); require_once('./libs/phpseclib/SFTP.php'); require_once("./libs/phpseclib/Crypt/AES.php"); if(!isse

我试图这样做,我可以下载文件,但我有一个问题,不知道如何修复它你能帮我找到错误吗

什么也没发生。帮我把这件事做好。我不知道如何解决这个问题,所以我需要所有能得到的帮助

<?php

require("configuration.php");
require("include.php");

require_once('./libs/phpseclib/SFTP.php');
require_once("./libs/phpseclib/Crypt/AES.php");


if(!isset($_SESSION['clientid']))
{
    //DON'T KNOW HOW THE REQEUSTOR IS!!
    die();
}

$clientid = $_SESSION['clientid'];

$serverid = '';
$extendedPath = '';
$action = '';

if(!isset($_GET['serverid']) or !isset($_GET['path']) or !isset($_GET['action']))
{
    die();
}


$serverid = $_GET['serverid'];
$extendedPath = $_GET['path'];
$action = $_GET['action'];

$boxDetailsSQL = sprintf("SELECT box.boxid, box.ip, box.login, box.password, box.sshport, srv.path
                            FROM %sbox box
                            JOIN %sserver srv ON box.boxid = srv.boxid
                            JOIN %sgroupMember grpm ON (grpm.groupids LIKE CONCAT(srv.groupid, ';%%')
                                                      OR grpm.groupids LIKE CONCAT('%%;', srv.groupid, ';%%'))

                            WHERE srv.serverid = %d
                            AND grpm.clientid = %d;", DBPREFIX, DBPREFIX, DBPREFIX, $serverid, $clientid);

$boxDetails = mysql_query($boxDetailsSQL);
$rowsBoxes = mysql_fetch_assoc($boxDetails);

$aes = new Crypt_AES();
$aes->setKeyLength(256);
$aes->setKey(CRYPT_KEY);

$sftp= new Net_SFTP($rowsBoxes['ip'], $rowsBoxes['sshport']);

if(!$sftp->login($rowsBoxes['login'], $aes->decrypt($rowsBoxes['password'])))
{
    echo 'Failed to connect';
    die();
}


//ACTION SELECTOR
if($action == 'list')
{
    getlist($rowsBoxes, $extendedPath, $sftp);
}   

if($action == 'fileUpload')
{
    fileUpload($rowsBoxes, $extendedPath, $sftp);

}   

if($action == 'download')
{
    delete($rowsBoxes, $extendedPath, $sftp);   
}   

//ACTION FUNCTIONS

function download($rowsBoxes, $extendedPath, $sftp)
{
    $remoteFile = dirname($rowsBoxes['path']).'/'.trim($extendedPath.'/');
    $downloadfile $sftp->put($remoteFile);

    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($downloadfile));
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($downloadfile));
    readfile($downloadfile);

}

您正在调用
getList
fileUpload
delete
,具体取决于$\u GET['action']的值,但您根本没有调用
download
。您已经定义了该函数,但没有在代码段中调用它。在你的下载功能中

$downloadfile $sftp->put($remoteFile);
您可能应该这样做:

$downloadfile = $sftp->get($remoteFile);
另外,代替
filesize($downloadfile)
do
strlen($downloadfile)
readfile($downloadfile)
do
echo$downloadfile。如果要保存到本地文件,请执行以下操作:
$sftp->get($remoteFile,$downloadfile)

更新代码:

function download($rowsBoxes, $extendedPath, $sftp)
{
$remoteFile = dirname($rowsBoxes['path']).'/'.trim($extendedPath.'/');
$downloadfile = $sftp->get($remoteFile);

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($downloadfile));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . strlen($downloadfile));
echo $downloadfile;

}
如果要执行显示图像之类的操作,请执行以下操作:

function download($rowsBoxes, $extendedPath, $sftp)
{
$remoteFile = dirname($rowsBoxes['path']).'/'.trim($extendedPath.'/');
$downloadfile = $sftp->get($remoteFile);

$file_extension = strtolower(substr(strrchr($filename,"."),1));

switch( $file_extension ) {
    case "gif": $ctype="image/gif"; break;
    case "png": $ctype="image/png"; break;
    case "jpeg":
    case "jpg": $ctype="image/jpg"; break;
    default:
}

header('Content-type: ' . $ctype);
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
echo $downloadfile;

}

而是学习,并使用或。将帮助您做出决定。尝试向
die()
命令中添加一些消息,以便您知道它在哪里停止。另外,尝试添加
ini\u集('display\u errors',1);错误报告(-1)到文件顶部,让PHP显示所有错误。需要帮助下载文件。你说mysql不安全是什么意思?以
mysql\uu
开头的函数不再被维护,现在已经存在了。我需要的帮助就是这段代码。在这之后。“我需要帮助修复此代码。”而不是执行
filesize($downloadfile)
do strlen($downloadfile)`和
readfile($downloadfile)
do
echo$downloadfile。如果要保存到本地文件,请执行以下操作:
$sftp->get($remoteFile,$downloadfile)想要下载文件在网站上很热门。我该如何修复它?你必须编写代码,以便我更好地理解它?我已经更新了我的原始帖子,以包含你函数的重写版本。我正在尝试这样做,但它的工作方式与你的工作方式不同。但是当我在这里输入它时,下载文件并将其保存到web服务器。echo$sftp->get($remoteFile,'test.jpg');
function download($rowsBoxes, $extendedPath, $sftp)
{
$remoteFile = dirname($rowsBoxes['path']).'/'.trim($extendedPath.'/');
$downloadfile = $sftp->get($remoteFile);

$file_extension = strtolower(substr(strrchr($filename,"."),1));

switch( $file_extension ) {
    case "gif": $ctype="image/gif"; break;
    case "png": $ctype="image/png"; break;
    case "jpeg":
    case "jpg": $ctype="image/jpg"; break;
    default:
}

header('Content-type: ' . $ctype);
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
echo $downloadfile;

}