php - 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";
}
}
?>
解决方案
从您的文件中:
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 文件中。
推荐阅读
- applescript - 使用 AppleScript 从 .txt 文件中读取时间/日期变量
- makefile - 用于检查拼写的 Makefile
- react-native - 警告:forwardRef 渲染函数只接受两个参数:props 和 ref。您是否忘记使用 ref 参数?本机基础
- c# - System.ArgumentException: 'myObject' 类型的对象无法转换为'System.Collections.Generic.List`1[myObject]' 类型。
- bash - Bash jq 包含搜索键
- node.js - 我有多个相互引用的猫鼬模式。我正在使用 gql-compose-mongoose。如何将一个文档的 objectID 推送到另一个文档中?
- c# - 在其视图模型(Prism WPF)中动态加载用户控件和设置属性
- solr - 如何通过管理 API 创建 Solr 核心而不使用配置文件创建实例目录?
- google-cloud-vision - Cloud Vision API 是否有办法获取键值对作为响应,就像他们的 AWS Textract 对应物一样?
- php - Laravel 计划在 Windows 中使用任务计划不工作