Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/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
通过sftp php连接到服务器_Php_Curl_Ftp_Sftp_Fsockopen - Fatal编程技术网

通过sftp php连接到服务器

通过sftp php连接到服务器,php,curl,ftp,sftp,fsockopen,Php,Curl,Ftp,Sftp,Fsockopen,我们如何通过sftp连接到远程服务器,以验证登录详细信息在php中是否有效 我正在使用apache服务器。。。我的用途是检查用户输入的登录详细信息是否正确。是否安装了apache服务器?例如:xampp 如果是,则必须使用FTP功能: <?php $connection = ssh2_connect('ftp.server.com', 22); //port 22 for Shell connections ssh2_auth_password($connection, 'username

我们如何通过sftp连接到远程服务器,以验证登录详细信息在php中是否有效


我正在使用apache服务器。。。我的用途是检查用户输入的登录详细信息是否正确。

是否安装了apache服务器?例如:xampp

如果是,则必须使用FTP功能:

<?php
$connection = ssh2_connect('ftp.server.com', 22); //port 22 for Shell connections
ssh2_auth_password($connection, 'username', 'password');

$shell_ftp = ssh2_sftp($connection);

$connectionStream = fopen('ssh2.sftp://'.$shell_ftp.'/path/to/fileorfolder', 'r');

if(!connectionStream)
{
    echo "Could not connect to the server, please try agian";
}
else
{
    echo "Successfully logged in.";
}
?>

如果是基本的Shell FTP连接,您必须定义文件或文件夹的绝对路径。

这有帮助吗

<?php
$connection = ssh2_connect('ftp.server.com', 22); 
if (ssh2_auth_password($connection, 'username', 'password')) 
    echo "Authentication success";
else 
    echo "Authentication failure";
?>

您可能会更容易使用。下面是一个例子:

<?php
include('Net/SFTP.php');

$sftp = new Net_SFTP('www.domain.tld');
if (!$sftp->login('username', 'password')) {
    exit('Login Failed');
}

echo $sftp->pwd() . "\r\n";
$sftp->put('filename.ext', 'hello, world!');
print_r($sftp->nlist());
?>


正如大家所建议的那样,libssh2的问题在于它没有得到广泛的部署,它的API不是最可靠的,它不可靠,支持不好,等等。

我用多种建议组成了一个小库。我鼓励


听说过apache和http吗?不。。。不完全是。。。curl、fsock、ftp功能等都可以。有没有什么原因使sftp的登录凭据不起作用?这比我的答案好。你怎么知道连接成功与否。。。不会有任何文件操作。。。只需要验证用户名和密码…我不需要这一行$connectionStream=fopen('ssh2.sftp://'.$shell_ftp.'/path/to/fileorfolder,'r')也用于测试我正在使用端口号为2275的服务器。那会是个问题吗。原因启动SSH连接时出错(-1):发送bannerWell失败,如果要检查登录是否有效。然后您将需要该行来检查$connectStream是打开的还是关闭的,并且最好使用端口22作为shell。