-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Hello!
- I would recommend using the factory pattern to create a custom client.
For example the final code might look like this:
$sftpClientFactory = $this->get('nw.sftp');
$sftp = $sftpClientFactory->create($host, $port);
$sftp->login($username, $password);
$sftp->loginWithKey($host, $username, $pubkeyfile, $privkeyfile, $passphrase = null);
What problems will it solve?
- You can use more than one connection at the same time. When designing, it should always be considered that if one connection is required at the moment, then most likely in the future more will need to be used.
- The service cannot store state by its own architecture. And if it stores the state (if absolutely necessary) then you need to implement the ResetInterface interface from the Symfony package. Otherwise it can cause problems when using an immortal lifecycle (RoadRunner, ReactPHP, etc).
-
You need rewrite disconnect function. Please use https://www.php.net/manual/en/function.ssh2-disconnect.php, otherwise it can create big problems when using an long lifecycle.
-
You cannot use file_get_contents() / file_put_contents() for large files. when used, the file is read entirely into memory and when working with large files, memory will run out. use fread() / fwrite() instead.
-
Need to handle authentication errors according https://www.php.net/manual/en/function.ssh2-auth-password.php . For example, you can use custom error handler for getting error message.
-
I didn't quite understand how the commands work, given that the connection is not being established.