GithubHelp home page GithubHelp logo

yii2-gsftp's People

Contributors

arssirek avatar diegotibi avatar hguenot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

yii2-gsftp's Issues

Versions confusion

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?

Interface differs from the FTP one.

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.

Can not append to a remote file.

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:

  • The raw ssh connection handler on the driver, so I can extend it and implement the needed behaviors with an SSH connection already initialized.
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;
    }
  • The driver instance on the component so it is accessible and allow accessing the new methods defined in the extended driver within the component descendant.
    /**
     * 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);
    }
  • The method for the connection parsing (parseConnectionString), so I can force my driver for the particular sftp connection string, so it is transparent on the application configuration.
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);
        }
    }

How it works?

Hi!

Please, how it works? How can I use it from action controller?

Thx!

Invalid configuration

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.

Timeout property not actually respected in the SFTP internals.

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());
	}

So many error in this extension!!!!

Undefined variable: user

# 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]));
    }

correct

'data'=>$user --> 'data' => $this->handle->user

so many error in this extension,please check !

How to move remote file to another remote directory

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!

fileExists working for dir not for files

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

Setting unknown property: gftp\drivers\SftpDrive

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

Error on upload file - namespace of phpseclib changed

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?

how to call execute() function

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.

Error when using ls('dirname',true,true)

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.