简体   繁体   中英

How to set a custom SFTP port with phpseclib

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');
}
?>

It is showing "Login Failed".

You can define a custom port like so:

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

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)
{

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM