Yii 1.1: sftp

Extension for SFTP
11 followers

Simple extension for managing SFTP functions.

Requirements

Yii 1.1 or above

Usage

  1. Put extracted sftp folder to extension directory.
  2. Below code snaps shows how to setup and use it with yii environment.
'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 2 comments

#16021 report it
dhanakumar at 2014/01/10 05:03am
How to generate xls file in sftp.. ?

i'm using the extension sftp..

when moving files from LOCAL to SFTP there is no problem.. but i need to generate xls (using PEAR)file in SFTP ... how to achieve this .. ?

#5551 report it
yagoozle at 2011/10/20 12:33am
suggestion: use phpseclib, a pure PHP SFTP implementation

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 to leave your comment.

Create extension