Help yii2-gsftp.

Hello Yii devs.

I need to use a sftp extension for my app so I chose yii2-gsftp but I can’t find a documentation on how to use it.

All I found was configuring Yii2 with the sftp server data.

I need to know how do I use it, how do I create a sftp object and execute commands on the server based on the object etc.

Thanks in advance.

Hello Yii devs.

I found what i was looking for myself, so i share it for anyone who might need it in the future.

basically you load yii2-gsftp as a component in common/config/main-local.php




return [

    // [...]

    'components'=>[

        // [...]

        'sftp' => [

            'class' => '\gftp\FtpComponent',

            'driverOptions' => [

                'class' => \gftp\FtpProtocol::valueOf('sftp')->driver,

                'user' => 'root', // your server data

                'pass' => 'PassW0rd', // your server data

                'host' => 'host', // your server data

                'port' => 22,

                'timeout' => 120

            ]

        ]

    ],

    // [...]

];



Then to use this component to create a connection and login:




Yii::$app->sftp->connect();

Yii::$app->sftp->login();




After this you can execute sftp commands e.g.




Yii::$app->sftp->get($localPath, $remotePath, FTP_ASCII, false);


Yii::$app->sftp->close();



You close the connection and you are done.

I coundt find any documentation on this so i hope this helps you.