Given PHP 7.2, php ssh2 extension and Ubuntu 18.04.1 LTS. I want to communicate with imap server through ssh server.
Direct connection:
$stream = fsockopen('ssl://imap.gmail.com', 993);
for($i = 0; $i<=5; $i++){
var_dump(fgets($stream));
sleep(2);
}
Result:
"* OK Gimap ready for requests from 178.150.167.73 u11mb208610367lfc
"
Connection through ssh:
$ssh_conn = ssh2_connect($sshIp, $sshPort);
if ($ssh_conn && ssh2_auth_password($ssh_conn, $sshUsername, $sshPassword)) {
$stream = ssh2_tunnel($ssh_conn, 'imap.gmail.com', 993);
for ($i = 0; $i <= 5; $i++) {
var_dump(fgets($stream));
sleep(2);
}
}
Output:
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
Ssh server 100% working. I tried it with another tools including extra php extension for imap via ssh. But I need to use exactly this direct way.