hguenot / yii2-gsftp Goto Github PK
View Code? Open in Web Editor NEWyii2-gftp extension allow usage of SFTP in FTP component.
License: GNU Lesser General Public License v3.0
yii2-gftp extension allow usage of SFTP in FTP component.
License: GNU Lesser General Public License v3.0
Hi @hguenot , thanks for the work on this project,
I am a bit confused with versions here, I started to use the project a year ago, and tried to update the system to work with php 7.2 now, There was an issue with the Object class name, but the actual problem for me turned out to be that composer doesn't update this repository automatically.
the error I received:
PHP Fatal error: Declaration of
gftp\drivers\SftpDriver::get($remote_file, $local_file = NULL, $mode = gftp\drivers\FTP_ASCII, $asynchronous = false)
must be compatible with
gftp\drivers\RemoteDriver::get($remote_file, $local_file = NULL, $mode = gftp\drivers\FTP_ASCII, $asynchronous = false, ?callable $asyncFn = NULL)
in ../vendor/hguenot/yii2-gsftp/drivers/SftpDriver.php on line 15
I see that the code on the github was updated with the commit
But can't get composer to see that.. which is probably an issue to composer, but I decided to post it here as I may be not the only one with the issue, it is fine with you, right?
It worked only after I run an update with commit version
composer require hguenot/yii2-gsftp dev-master#d2d22ac70df744daf3bcee596a7641ac82aa4122
But is there any other, recommended, way to update I missed?
There is no mention about all the driver options and that there is a difference between this and the other driver.
There is at least one however - the passive
flag.
If client is configured through the DSN, and has the passive flag present.
Once the configuration is changed from
'componentName' => [
'class' => 'app\components\FtpComponent',
'connectionString' => 'ftp://user:pass@host:21',
'driverOptions' => [
'timeout' => 120,
'passive' => 120,
],
],
to
'componentName' => [
'class' => 'app\components\FtpComponent',
'connectionString' => 'sftp://user:pass@host:22',
'driverOptions' => [
'timeout' => 120,
'passive' => 120,
],
],
It will fail to instantiate the client. This means that the two drivers are not the same and they are not interchangeable.
My porposal is to add a passive
option to mimic the FTP driver and fully ignore it internally. Functionally it will be the same ini reality wil reduce chances of this issue.
The FTP extension did not support append due to PHP internals having issues with that (resolved in 7.2).
However this one based on the ssh connection does support appending to a remote file.
Is there an option to expose that or somehow allow other to extent the driver and implement the append logic on top of this driver.
As it is, it is impossible, as some very important bits are private and are non-accessible to anyone that wants to access them (while extending the class), essentially preventing a meaningful extension.
I've solved it but had to copy the driver and the component classes out of the extension, so I can tweak the visibility to protected for:
public function append($local_file, $remote_file = null)
{
$this->connectIfNeeded();
if (!isset($remote_file) || $remote_file == null || !is_string($remote_file) || trim($remote_file) == "") {
$remote_file = basename($local_file);
}
$mode = SFTP::SOURCE_LOCAL_FILE | SFTP::RESUME_START | SFTP::RESUME;
if (!$this->handle->put($remote_file, $local_file, $mode)) {
throw new FtpException(
\Yii::t('app', 'Could not append file "{local_file}" on "{remote_file}" on server "{host}"', [
'host' => $this->getHost(),
'remote_file' => $remote_file,
'local_file' => $local_file
])
);
}
return $remote_file;
}
/**
* Appends the contents of a local file to a remote FTP one.
*
* @param string $localFile Path to a local file to send contents of.
* @param string $remoteFile Path to a remote file to append data to.
* @return int Bytes written to the remote file.
*
* @throws FtpException
* - On failing to read the local file.
* - On Failing to write to the remote file.
* - When the written data amount is incorrect.
*/
public function append($localFile, $remoteFile)
{
$this->connectIfNeeded();
return $this->handle->append($localFile, $remoteFile);
}
protected function parseConnectionString()
{
// Call the parent.
parent::parseConnectionString();
// Hijack the driver class implementation
$options = $this->getDriverOptions();
if ($options['class'] === 'gftp\drivers\SftpDriver') {
$options['class'] = TheNewDriver::class;
$this->setDriverOptions($options);
}
}
Hi!
Please, how it works? How can I use it from action controller?
Thx!
Hi there,
When using the second configuration example from the using section, with the direct protocol, I get the following error:
Unknown Property โ yii\base\UnknownPropertyException
Setting unknown property: gftp\FtpComponent::timeout
When removing the 'timeout' => 120 line, I get the following error:
Invalid Configuration โ yii\base\InvalidConfigException
Object configuration must be an array containing a "class" element.
The basic usage configuration example works for me.
Implements method fileExists in SFtpDriver
The only way to inject timeout into the SFTP connection instance is trough the constructor.
class SFTP extends SSH2
{
// ...
/**
* Default Constructor.
*
* Connects to an SFTP server
*
* @param string $host
* @param int $port
* @param int $timeout
* @return \phpseclib\Net\SFTP
* @access public
*/
function __construct($host, $port = 22, $timeout = 10)
// ...
}
This library maintains an unused timeout property that is never passed to the underlying connection handler. like so:
public function connect() {
$this->handle = new SFTP($this->host, $this->port);
}
This will work as expected if it was implemented like:
public function connect() {
$this->handle = new SFTP($this->host, $this->port, $this->getTimeout());
}
# in D:\website\flxx2\basic\vendor\hguenot\yii2-gftp\FtpComponent.php at line 179
public function login () {
$this->connectIfNeeded(false);
$this->handle->login();
$this->onLogin(new Event(['sender' => $this, 'data' => $user]));
}
'data'=>$user
--> 'data' => $this->handle->user
so many error in this extension,please check !
Hi!
I've been looking for a method to copy files in remote directories. Something like:
$remote_file = '/remote/directory/myfile.txt'
$remote_target_path = '/remote/directory/target/';
Yii::$app->ftp->movefile($remote_ofile, $remote_target_path);
I've tried using:
Yii::$app->ftp->rename($oldname, $newname);
But it does not work!
Any suggestion?
Thanks!
method \gftp\FtpComponent::fileExists not working for files
in file drivers/SftpDriver.php:281
please use phpseclib/Net/SFTP::file_exists method instead phpseclib/Net/SFTP::nlist
Hi,
I have an issue with the connection to the sftp in linux, in windows works, I have the following error:
PHP Fatal error: Uncaught exception 'yii\base\UnknownPropertyException' with message 'Setting unknown property: gftp\drivers\SftpDriver::handle' in .../vendor/yiisoft/yii2/base/Object.php:161
the configuration:
'ftp' => [
'class' => '\gftp\FtpComponent',
'connectionString' => 'sftp://user:password@url:22',
'driverOptions' => [ 'timeout' => 120 ]
],
Any idea?
Regards
Hi, we experience an error on class SFTP
PHP Fatal error: Class 'phpseclib\Net\SFTP' not found in /var/www/io/vendor/hguenot/yii2-gsftp/drivers/SftpDriver.php on line 125
Error: Class 'phpseclib\Net\SFTP' not found
Can you help us?
Hi,
I am able to SSH and list the files using ls command
$files = Yii::$app->gftp->ls();
but how to call the execute() function....??
$files = Yii::$app->gftp->execute("some command");
please let me know.
When using FtpComponent::ls() with both 'full' and 'recursive' parameters set to true an error is thrown: "Cannot use object of type stdClass as array"
The parse() method expects an array but receives objects
When setting the full param to false everything works fine
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.