Skip to content

Unable to open SFTP connection

I have to read CSV files from an ftp and copy it to my magento2 var folder.

I’m getting this exception Exception #0 (Exception): Unable to open SFTP connection

When I tried with main cpanel user,it seems to be working. But it is not working with ftp login that I created using the main cpanel user.

Pasting the code below.

public function __construct(

................................

MagentoFrameworkFilesystemIoSftp $ftp,

...................................

)

{

..............

$this->ftp = $ftp;

.................

}

 $fthost = 'ip-addreess';
        $ftusername = '[email protected]';
        $ftpwd = 'password';
        $ftport = '21';
    $open = $this->ftp->open(
        array(
            'host' => $fthost,
            'username' => $ftusername,
            'password' => $ftpwd,
            'port' => $ftport,
            'ssl' => true,
            'passive' => true
            )
    );
   // echo 'test';
    //var_dump($this->ftp->ls()); exit;
    //$ftp_open_stat = 1;
    $logger->info('Move File from Server');
    /* MOVE FILE FROM REMOTE TO SERVER */

    $result = $this->ftp->read('/home1/dev/public_html/test/test.csv', '/var/www/html/magetest/var/sync/test.csv');