Simple extension for managing SFTP functions.
Yii 1.1 or above
'import'=>array( 'application.extensions.sftp.*', ) 'components'=>array( 'sftp'=>array( 'class'=>'SftpComponent', 'host'=>'127.0.0.1', 'port'=>22, 'username'=>'test', 'password'=>'test.1', ), ), //example 1 try { // Listing files Yii::app()->sftp->connect(); $cur_dir = Yii::app()->sftp->getCurrentDir() . '/'; $files = Yii::app()->sftp->listFiles($cur_dir); } catch(Exception $e) { echo $e->getMessage(); } //example 2 try { $sftp_obj = new SftpComponent('127.0.0.1', 'test', 'test.1'); $sftp_obj->connect(); $cur_dir = $sftp_obj->getCurrentDir() . '/'; $files = $sftp_obj->listFiles($cur_dir); } catch(Exception $e) { echo $e->getMessage(); } // Available methods $sftp_obj->chdir() // Change directory $sftp_obj->chmod() // Change permission $sftp_obj->chown() // Change ownership $sftp_obj->createDirectory() // Create directory on remote location $sftp_obj->execCmd() // Execute os commands $sftp_obj->getAtime() // Get file created date/time $sftp_obj->getCurrentDir() // Get current directory path $sftp_obj->getFile() // Retrieve file from remote location $sftp_obj->getMdtm() // Get file modified date/time $sftp_obj->getSize() // Get file size $sftp_obj->isDir() // Check for directory $sftp_obj->listFiles() // List directory content $sftp_obj->removeDirectory() // Remove directory on remote location $sftp_obj->removeFile() // Remove file $sftp_obj->sendFile() // Send file to remote location
Total 1 comment
The PECL ssh2 extension is notoriously difficult to install and on a lot of web hosts you're not going to be able to install extensions anyway. I think you should use phpseclib, a pure PHP SFTP implementation.
All phpseclib requires is that the preg_* functions be available (I've never seen a web server where they weren't although it is possible to disable them, in theory, with a flag when compiling PHP) and that fsockopen work.
Leave a comment
Please login to leave your comment.