SSH Library



( ZN > 3.0.6 )

SSH (Secure Shell) is a cryptographic network protocol for secure data transmission. Data transfer between two computers connected to the network via ssh is done over an unsecured network over the security channel. In this case, one of the machines communicating with Ssh on the network will be the ssh server and the other ssh client. The terms of this protocol are separated by two major versions, SSH-1 and SSH-2 .

Ssh is best known for its protocol implementation in Unix and similar operating systems to access shell accounts, but it can also be used to access accounts on Windows. Ssh is designed to provide secure data transmission instead of insecure protocols (such as the Berkeley rsh and rexec protocols) that access Telnet and other remote shells.

In the ZN Framework we will also try to give some insight into how to use SSH.

 

# Configuration


Below is the sequence used to configure ssh connection settings.

File: Config / Services.php
SSH
String $ host = '' Host name.
String $ user = '' User name.
String $ password = '' User password.
Int $ port = 22 Connection port.
Array $ methods = [] Methods.
Array $ callbacks = [] Callback functions.

 

# Methods


this differentConnect ( Array $ config )
this command ( String $ command )
Mixed run ( String $ command = NULL )
String output ( Int $ length = 4096 )
Bool upload ( String $ localPath , String $ remotePath )
Bool download ( String $ remotePath , String $ localPath )
Bool createFolder ( String $ path , Int $ mode = 0777 , Bool $ recursive = true )
Bool deleteFolder ( String $ path )
Bool deleteFile ( String $ path )
Bool rename ( String $ oldName , String $ newName )
Bool permission ( String $ path , Int $ type = 0775 )

 

# DifferentConnection ( ZN> = 4.0.0 )


The server configuration file is used to provide a different set of connection settings.

Parameters

Array $ config Connection settings.
return this

Use of

$config = 
[
    'host'     => 'localhost',
    'user'     => 'test',
    'password' => 'zntr'
];

$dssh = SSH::differentConnection($config);
$dssh->command('usr/local/bin/php -i')->run();

 

# Command ( ZN > 3.0.6 )


The command is used to run the line. You can provide multiple commands with a single line or multiple uses of the command () method.

Parameters

String $ commander The command to run.
return this

Use of

SSH::connect($config)
   ->command('/usr/local/bin/php -i')
   ->command('/usr/bin/ls public_html/images')
   ->run();

 

# Run ( ZN > 3.0.6 )


Used to execute sent commands. Used as a final method.

Parameters

String $ command = NULL It is an alternative to the command () function. Usage is not compulsory.
return this

Use of

SSH::connect($config)
   ->command('/usr/local/bin/php -i')
   ->command('/usr/bin/ls public_html/images')
   ->run();

 

# Output ( ZN > 3.0.6 )


It is used to print the result screen at the end of the process.

Parameters

Int $ length = 4096 The length in bytes of the output will be how many characters in length.
return String

Use of

SSH::output();

 

# Upload ( ZN > 3.0.6 )


Used to upload files to the server.

Parameters

String $ localPath File to load.
String $ remotePath Where to upload to the server.
return Bool

Use of

SSH::upload('local/example.txt', 'remote/example.txt');

 

# Download ( ZN > 3.0.6 )


Used to download files from the server.

Parameters

String $ remotePath Where to upload to the server.
String $ localPath File to load.
return Bool

Use of

SSH::upload('remote/example.txt', 'local/example.txt');

 

# CreateFolder ( ZN> = 3.0.6 )


Used to index the server.

Parameters

String $ path The directory to be created.
Int $ mode = 0777 Permission to create files.
Bool $ recursive = true Indexing inside.
return Bool

Use of

SSH::createFolder('remote/example');

 

# DeleteFolder ( ZN > 3.0.6 )


Used to delete directories from the server.

Parameters

String $ path The directory to be created.
return Bool

Use of

SSH::deleteFolder('remote/example');

 

# DeleteFile ( ZN > 3.0.6 )


Used to delete files from the server.

Parameters

String $ path The file to delete.
return Bool

Use of

SSH::deleteFile('remote/example.txt');

 

# Rename ( ZN > 3.0.6 )


Used to change the name of the file or directory contained in the server.

Parameters

String $ Oldname Game The old name of the file.
String $ NewName The new name for the file.
return Bool

Use of

SSH::rename('remote/example.txt', 'remote/new-example.txt');

 

# Permission ( ZN > 3.0.6 )


Used to change the authority mode of the file.

Parameters

String $ path File name.
Int $ type = 0775 File mode.
return Bool

Use of

SSH::permission('remote/example.txt', 0644);