Simple extension for managing SFTP functions.
Requirements ¶
Yii 1.1 or above
Usage ¶
- Put extracted sftp folder to extension directory.
- 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
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.
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 .. ?
I am facing issue
PHP Error[2]: unpack(): Type C: not enough input, need 1, have 0
it is working on same local syste, but with another Server it throw an Error.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.