0
votes

Hello their i am getting error in this code with trellis server but it is working on other server perfectly

<?php
 $localfile      = 'test.txt';
 $sftpServer    = 'x';
 $sftpUsername  = 'x';
 $sftpPassword  = 'x';
 $sftpPort      = 22;
 $sftpRemoteDir = '/';

 $ch = curl_init('sftp://' . $sftpServer . ':' . $sftpPort . $sftpRemoteDir . '/' . 
   basename($localfile));

 $fh = fopen($localfile, 'r');

if ($fh) {

curl_setopt($ch, CURLOPT_USERPWD, $sftpUsername . ':' . $sftpPassword);
curl_setopt($ch, CURLOPT_UPLOAD, true);
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_SFTP);
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
// curl_setopt($ch, CURLOPT_FTP_SSL, FALSE);
curl_setopt($ch, CURLOPT_INFILE, $fh);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
curl_setopt($ch, CURLOPT_VERBOSE, true);

$verbose = fopen('php://temp', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $verbose);

$response = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);

if ($response) {
    echo "Success";
} else {
    echo "Failure";
    rewind($verbose);
    $verboseLog = stream_get_contents($verbose);
    echo "Verbose information:\n" . $verboseLog . "\n";
}
 }
 ?>

The error i got in my trellis server

The error is: "resource(3) of type (stream) FailureVerbose information: * Trying ipaddredds:22... * TCP_NODELAY set * Connected to ftp.example.ch (ip addreass) port 22 (#0) * User: user* Failure establishing ssh session * Closing connection 0 "

Hi Jay, there could be server specific conditions. The port 22 may be blocked as a default ssh port. Try to change port, read in hosting docs and in trellis docs. Let us know if it solves the problem.cssBlaster21895
but it working on another server well same sftp but it not run on trellisJaY KuMaR
thanks for your response dear ;DJaY KuMaR
you have to check if your server policy blocks default port 22cssBlaster21895