Class Shell
Allows in/out operations and/or data validations with a local (bash) or remote computer (like ssh, scp, etc.).
Inherited Members
Namespace: AutoCheck.Core.Connectors
Assembly: AutoCheck.Core.dll
Syntax
public class Shell : Base
Constructors
| Improve this Doc View SourceShell()
Creates a new local shell connector instance.
Declaration
public Shell()
Shell(Utils.OS, String, String, String, Int32)
Declaration
public Shell(Utils.OS remoteOS, string host, string username, string password, int port = 22)
Parameters
Type | Name | Description |
---|---|---|
Utils.OS | remoteOS | |
System.String | host | |
System.String | username | |
System.String | password | |
System.Int32 | port |
Shell(String, String, String, String, Int32)
Declaration
public Shell(string remoteOS, string host, string username, string password, int port = 22)
Parameters
Type | Name | Description |
---|---|---|
System.String | remoteOS | |
System.String | host | |
System.String | username | |
System.String | password | |
System.Int32 | port |
Properties
| Improve this Doc View SourceHost
The remote host address.
Declaration
public string Host { get; }
Property Value
Type | Description |
---|---|
System.String |
IsLocal
Returns true if the current Shell instance has been instanced into local mode, false otherwise.
Declaration
public bool IsLocal { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsRemote
Returns true if the current Shell instance has been instanced into remote mode, false otherwise.
Declaration
public bool IsRemote { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Password
The remote host password used to login.
Declaration
public string Password { get; }
Property Value
Type | Description |
---|---|
System.String |
Port
The remote host port, where SSH is listening to.
Declaration
public int Port { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
RemoteOS
The remote host OS.
Declaration
public Utils.OS RemoteOS { get; }
Property Value
Type | Description |
---|---|
Utils.OS |
Username
The remote host username used to login.
Declaration
public string Username { get; }
Property Value
Type | Description |
---|---|
System.String |
Methods
| Improve this Doc View SourceCountFiles(String, Boolean)
Returns how many files has been found within the given path.
Declaration
public virtual int CountFiles(string path, bool recursive = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path where the files will be searched into. |
System.Boolean | recursive | Recursive deep search. |
Returns
Type | Description |
---|---|
System.Int32 | The amount of files. |
CountFiles(String, String, Boolean)
Returns how many files has been found within the given path.
Declaration
public int CountFiles(string path, string searchpattern, bool recursive = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path where the files will be searched into. |
System.String | searchpattern | The folder search pattern. |
System.Boolean | recursive | Recursive deep search. |
Returns
Type | Description |
---|---|
System.Int32 | The amount of files. |
CountFolders(String, Boolean)
Returns how many folders has been found within the given path.
Declaration
public virtual int CountFolders(string path, bool recursive = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path where the folders will be searched into. |
System.Boolean | recursive | Recursive deep search. |
Returns
Type | Description |
---|---|
System.Int32 | The amount of folders. |
CountFolders(String, String, Boolean)
Returns how many folders has been found within the given path.
Declaration
public int CountFolders(string path, string searchpattern, bool recursive = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path where the folders will be searched into. |
System.String | searchpattern | The folder search pattern. |
System.Boolean | recursive | Recursive deep search. |
Returns
Type | Description |
---|---|
System.Int32 | The amount of folders. |
Dispose()
Disposes the object releasing its unmanaged properties.
Declaration
public override void Dispose()
Overrides
| Improve this Doc View SourceDownloadFile(String, String)
Downloads the remote file into the local system.
Declaration
public string DownloadFile(string file, string folder = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | file | The file to get including its path. |
System.String | folder | The folder where the file will be downloaded. |
Returns
Type | Description |
---|---|
System.String | The local file path once downloaded. |
DownloadFolder(String, Boolean)
Downloads the remote file into the local system.
Declaration
public string DownloadFolder(string path, bool recursive)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file to get including its path. |
System.Boolean | recursive | The entire file and folder structure will be downloaded recursivelly. |
Returns
Type | Description |
---|---|
System.String | The local file path once downloaded. |
DownloadFolder(String, String, Boolean)
Downloads the remote file into the local system.
Declaration
public string DownloadFolder(string path, string folder = null, bool recursive = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The file to get including its path. |
System.String | folder | The folder where the file will be downloaded. |
System.Boolean | recursive | The entire file and folder structure will be downloaded recursivelly. |
Returns
Type | Description |
---|---|
System.String | The local folder path once downloaded. |
ExistsFile(String)
Determines if a file exists.
Declaration
public bool ExistsFile(string file)
Parameters
Type | Name | Description |
---|---|---|
System.String | file | The file to get including its path. |
Returns
Type | Description |
---|---|
System.Boolean |
ExistsFile(String, String, Boolean)
Determines if a file exists.
Declaration
public bool ExistsFile(string path, string file, bool recursive = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path where the file will be searched into. |
System.String | file | The file to search. |
System.Boolean | recursive | Recursive deep search. |
Returns
Type | Description |
---|---|
System.Boolean | If the file exists or not. |
ExistsFolder(String)
Determines if a folder exists.
Declaration
public bool ExistsFolder(string folder)
Parameters
Type | Name | Description |
---|---|---|
System.String | folder | The folder to get including its path. |
Returns
Type | Description |
---|---|
System.Boolean |
ExistsFolder(String, String, Boolean)
Determines if a folder exists.
Declaration
public bool ExistsFolder(string path, string folder, bool recursive = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path where the folder will be searched into. |
System.String | folder | The folder to search. |
System.Boolean | recursive | Recursive deep search. |
Returns
Type | Description |
---|---|
System.Boolean | If the folder exists or not. |
GetFile(String, String, Boolean)
Returns the first file's path found, using the given file name or search pattern.
Declaration
public virtual string GetFile(string path, string file, bool recursive = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path where the file will be searched into. |
System.String | file | The file to search (searchpattern). |
System.Boolean | recursive | Recursive deep search. |
Returns
Type | Description |
---|---|
System.String | File's full path, NULL if does not exists. |
GetFiles(String, Boolean)
Returns a set of file's path found, using the given file name or search pattern.
Declaration
public virtual string[] GetFiles(string path, bool recursive = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path where the file will be searched into. |
System.Boolean | recursive | Recursive deep search. |
Returns
Type | Description |
---|---|
System.String[] | File's full paths. |
GetFiles(String, String, Boolean)
Returns a set of file's path found, using the given file name or search pattern.
Declaration
public string[] GetFiles(string path, string searchpattern, bool recursive = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path where the file will be searched into. |
System.String | searchpattern | The folder search pattern. |
System.Boolean | recursive | Recursive deep search. |
Returns
Type | Description |
---|---|
System.String[] | File's full paths. |
GetFolder(String, String, Boolean)
Returns the first folder's path found, using the given folder name or search pattern.
Declaration
public virtual string GetFolder(string path, string folder, bool recursive = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path where the folder will be searched into. |
System.String | folder | The folder to search (searchpattern). |
System.Boolean | recursive | Recursive deep search. |
Returns
Type | Description |
---|---|
System.String | Folder's full path, NULL if does not exists. |
GetFolders(String, Boolean)
Returns a set of folder's path found, using the given folder name or search pattern.
Declaration
public virtual string[] GetFolders(string path, bool recursive = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path where the folders will be searched into. |
System.Boolean | recursive | Recursive deep search. |
Returns
Type | Description |
---|---|
System.String[] | Folder's full path. |
GetFolders(String, String, Boolean)
Returns a set of folder's path found, using the given folder name or search pattern.
Declaration
public string[] GetFolders(string path, string searchpattern, bool recursive = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | Path where the folders will be searched into. |
System.String | searchpattern | The folder search pattern. |
System.Boolean | recursive | Recursive deep search. |
Returns
Type | Description |
---|---|
System.String[] | Folder's full path. |
Run(String, Int32)
Runs a shell command.
Declaration
public (int code, string response) Run(string command, int timeout = 0)
Parameters
Type | Name | Description |
---|---|---|
System.String | command | The command to run. |
System.Int32 | timeout | Timeout in milliseconds, 0 for no timeout. |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Int32, System.String> | The return code and the complete response. |
Run(String, String, Int32)
Runs a shell command.
Declaration
public (int code, string response) Run(string command, string path, int timeout = 0)
Parameters
Type | Name | Description |
---|---|---|
System.String | command | The command to run. |
System.String | path | The path where the command must run. |
System.Int32 | timeout | Timeout in milliseconds, 0 for no timeout. |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Int32, System.String> | The return code and the complete response. |
TestConnection()
Test the connection to the remote host, so an exception will be thrown if any problem occurs.
Declaration
public void TestConnection()
Wait(Int32)
The current thread execution will sleep for the given time.
Declaration
public void Wait(int milliseconds)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | milliseconds | The time to sleep. |