Simple OOP FTP library
这个扩展是对常用ftp函数的面向对象封装。
Resources ¶
Documentation ¶
Requirements ¶
- Yii 1.0 or above
Installation ¶
- Extract ftp folder under
protected/extensions
Usage ¶
The following code is the component registration in the config file:
'components'=>array(
'ftp'=>array(
'class'=>'application.extensions.ftp.EFtpComponent',
'host'=>'127.0.0.1',
'port'=>21,
'username'=>'yourusername',
'password'=>'yourpassword',
'ssl'=>false,
'timeout'=>90,
'autoConnect'=>true,
),...
)
See the following code example:
$ftp = Yii::app()->ftp;
$ftp->put('remote.txt', 'D:\local.txt');
$ftp->rmdir('exampledir');
$ftp->chdir('aaa');
$ftp->currentDir();
$ftp->delete('remote.txt');
Change Log ¶
February 25, 2009 ¶
- Rename CFtpComponent to EFtpComponent
February 25, 2009 ¶
- Initial release.
Error handling
Hi!
The extension is very straightforward, and easy to use. I am having trouble with errorhandling though. If i perform an illegal command. (for example mkdir directory already exists) the program dies with a php error. If i put the command in a try catch structure i get the same result.
As far as i now, the ftp_mkdir command is not soppoused to couse php error, but return a 0 if the transaction wasnt succesfull.
What am i doing wrong? Has somebody got a solution?
Thanks!
solution1
Enclode code in try catch block and check what value returns ftp_mkdir command - if it is zero throw exception.
if ( ! ftp_mkdir(...) ) throw new CException('Error info ...', 404);
Error handling2
The problem, that the program dies at the ftp_mkdir line. I get the php error:
ftp_mkdir() [<a href='function.ftp-mkdir'>function.ftp-mkdir</a>]: Directory already exists
I cant error handle, becouse the program execution stops!
Error handling
It's because the way Yii handles warnings. These warnings are generated by php ftp functions, not EFtpComponent. To avoid it either disable warnings in php error handler:
or edit EFtpComponent and put @ before all ftp_* function calls.
Passive mode ?
Useful and easy to use but your forget the param for passive mode
It seems to be useful to add it in the constructor
ftp_pasv($this->_connection, $this->pasv);
@miles
Set properties of components in the code when initializes component
I know for working it, must put config in
main/config.php
file and set parameters. and so we can use and access it withYii::app()->ftp
.Now after created, in the
action
, how can change property of this components to have new instance of it? Or in other words how can set properties of components in the code when initializes component?some bug
I thinks this line:
if ((empty($this->username) AND empty($this->password)) AND !$login_result)
must be change to this:
if ((!empty($this->username) AND !empty($this->password)) AND !$login_result)
And so about "close()" function:
Don't need "throw new CDbException" beacuse when destroy function and auto call this function, appear throw error message for always.
And so this line must be before of
return true
:$this->_active = false; $this->_connection = null; $this->_errors = null;
I have problem when i send(put) the image file on the server (.jpg,.rar,*.docx). I will correct code. Add parameter in the class EFtpComponent.
I don,t use:
public function put($remote, $local, $mode=FTP_ASCII)
but it work:
public function put($remote, $local, $mode=FTP_BINARY).
This use in documentation i not see.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.