如何使用 phpseclib 设置自定义 SFTP 端口 [英] How to set a custom SFTP port with phpseclib

查看:49
本文介绍了如何使用 phpseclib 设置自定义 SFTP 端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用 PHP 连接到 SFTP 服务器.我为此使用了 phpseclib.我在 Internet 上找到了一些示例,但无法连接到 SFTP.我正在使用自定义端口 (2222) 连接到 SFTP.请告诉我在哪里可以定义自定义端口以连接到 SFTP.

I have to connect to SFTP server by using PHP. I am using phpseclib for that. I found some example on Internet, but I am not able to connect to SFTP. I am using a custom port (2222) to connect to SFTP. Please tell me where I can define custom port to connect to SFTP.

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

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

显示登录失败".

推荐答案

您可以像这样定义自定义端口:

You can define a custom port like so:

Net_SFTP('www.domain.tld', 2222);

当您查看 SFTP 类的构造函数时,您可以看到它,如下所示:

You can see it when you look in the constructor from SFTP class which is like this:

function Net_SFTP($host, $port = 22, $timeout = 10)
{

}

这篇关于如何使用 phpseclib 设置自定义 SFTP 端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆