我在下面有以下脚本,我尝试通过 FTP 模拟文件上传,但使用 phpseclib 将其更改为 SFTP。
该脚本会很好地回显,直到该行:
$upload = $conn_id->put($paths.'/'.$name, $filep, NET_SFTP_LOCAL_FILE); echo "upload == ".$upload."\n";
什么都没有发生或打印出来的地方。
这是完整的脚本:
<?
include('Net/SSH2.php');
if(!isset($_POST["submit"])){?>
<form action="upload.php" method="POST" enctype="multipart/form-data">
<table align="center">
<tr>
<td align="right">
Server:
</td>
<td>
<input size="50" type="text" name="server" value="">
</td>
</tr>
<tr>
<td align="right">
Username:
</td>
<td>
<input size="50" type="text" name="user" value="">
</td>
</tr>
<tr>
<td align="right">
Password:
</td>
<td>
<input size="50" type="text" name="password" value="" >
</td>
</tr>
<tr>
<td align="right">
Path on the server:
</td>
<td>
<input size="50" type="text" name="pathserver" >
</td>
</tr>
<tr>
<td align="right">
Select your file to upload:
</td>
<td>
<input name="userfile" type="file" size="50">
</td>
</tr>
</table>
<table align="center">
<tr>
<td align="center">
<input type="submit" name="submit" value="Upload image" />
</td>
</tr>
</table>
</form>
<?}
else
{
set_time_limit(300);//for setting
$paths=$_POST['pathserver'];
echo "paths == ".$paths."\n";
$filep=$_FILES['userfile']['tmp_name'];
echo "filep == ".$filep."\n";
$sftp_server=$_POST['server'];
echo "sftp_server == ".$sftp_server."\n";
$sftp_user_name=$_POST['user'];
echo "sftp_user_name == ".$sftp_user_name."\n";
$sftp_user_pass=$_POST['password'];
echo "sftp_user_pass == ".$sftp_user_pass."\n";
$name=$_FILES['userfile']['name'];
echo "name == ".$name."\n";
// set up a connection to ftp server
$conn_id = new Net_SSH2($sftp_server);
// login with username and password
$login_result = $conn_id->login($sftp_user_name, $sftp_user_pass);
// check connection and login result
if ((!$conn_id) || (!$login_result)) {
echo "SFTP connection has encountered an error!";
echo "Attempted to connect to $sftp_server for user $sftp_user_name....";
exit;
} else {
echo "Connected to $sftp_server, for user $sftp_user_name".".....";
}
echo "HERE "."\n";
// upload the file to the path specified
$upload = $conn_id->put($paths.'/'.$name, $filep, NET_SFTP_LOCAL_FILE);
echo "upload == ".$upload."\n";
// check the upload status
if (!$upload) {
echo "SFTP upload has encountered an error!";
} else {
echo "Uploaded file with name $name to $sftp_server ";
}
// close the FTP connection
ftp_close($conn_id);
}
?>