Class: SSH2Utils

SSH2Utils

new SSH2Utils()

Source:

Members

getConnReady

Source:
See:

runMultiple

Executes a set of multiple and sequential commands.
Source:

Methods

ensureEmptyDir(server, remotePath, then)

Ensure a remote directory exists and is empty
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remotePath String
then callback(err, ServerCredentials server, ssh2.Client conn)
Source:

ensureEmptyDirSudo(server, remotePath, then)

Ensure a remote directory exists and is empty
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remotePath String
then callback(err, ServerCredentials server, ssh2.Client conn)
Source:

ensureFileContains(server, remoteFile, contain, then)

Ensure a remote file contains a certain text piece of text
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remoteFile String
contain String
then callback(contains, err, ServerCredentials server, ssh2.Client conn)
Source:

ensureFileContainsSudo(server, remoteFile, contain, then)

Ensure a remote file contains a certain text piece of text
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remoteFile String
contain String
then callback(contains, err, ServerCredentials server, ssh2.Client conn)
Source:

ensureOwnership(server, remotePath, then)

Ensure a file belongs to connected user by sudo chmod -R /path
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remotePath String
then callback(err, ServerCredentials server, ssh2.Client conn)
Source:

exec(server, cmd, doneEach, done)

Executes a command and return its output like child_process.exec. non-interactive also take care of - remote program termination with ctrl+C If cmd is an array of string, they are executed in serie, respective output of each stdout / stderr is join then returned.
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
cmd String|[String]
doneEach callback(bool err, String stdout, String stderr, ServerCredentials server, ssh2.Client conn)
done callback(bool err, String stdout, String stderr, ServerCredentials server, ssh2.Client conn)
Source:

execOne(server, cmd, done)

Executes a command and return its output like child_process.exec. non-interactive also take care of - remote program termination with ctrl+C
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
cmd String
done callback(bool err, String stdout, String stderr, ServerCredentials server, ssh2.Client conn)
Source:

fileExists(server, remoteFile, then)

Tells if a file exists on remote by trying to open handle on it.
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remoteFile String
then callback(err, exists, ServerCredentials server, ssh2.Client conn)
Source:

fileExistsSudo(server, remoteFile, then)

Tells if a file exists on remote by trying to open handle on it.
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remoteFile String
then callback(err, exists, ServerCredentials server, ssh2.Client conn)
Source:

getDir(server, remotePath, localPath, allDone)

Downloads a remote directory to the local. remote traverse directories over sftp. then get files in parallel
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remotePath String
localPath String
allDone callback(err, ServerCredentials server, ssh2.Client conn)
Source:

getFile(server, remoteFile, localPath, then)

Downloads a file to the local
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remoteFile String
localPath String
then callback(err, ServerCredentials server, ssh2.Client conn)
Source:

mkdir(server, remotePath, then)

Creates a remote directory
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remotePath String
then callback(err, ServerCredentials server, ssh2.Client conn)
Source:

mkdirSudo(server, remotePath, then)

Creates a remote directory
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remotePath String
then callback(err, ServerCredentials server, ssh2.Client conn)
Source:

mktemp(server, suffix, then)

Creates a concurrent-safe temporary remote directory. It does not attempt to keep track of temp files created during the session. Thus it won t delete them on connection close.
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
suffix String
then callback(err, tmpDirName, ServerCredentials server, ssh2.Client conn)
Source:

putDir(server, localPath, remotePath, then)

Uploads a local directory to the remote. Partly in series, partly parallel. Proceed such sudo rm -fr /remotePath sudo mkdir -p /remotePath recursive sftp mkdir recursive sftp put
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
localPath String
remotePath String
then callback(err, ServerCredentials server, ssh2.Client conn)
Source:

putDirSudo(server, localPath, remotePath, then)

Uploads a local directory to the remote. Partly in series, partly parallel. Proceed such sudo rm -fr /remotePath sudo mkdir -p /remotePath recursive sftp mkdir recursive sftp put
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
localPath String
remotePath String
then callback(err, ServerCredentials server, ssh2.Client conn)
Source:

putFile(server, localFile, remoteFile, then)

Uploads a file on the remote remote
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
localFile String
remoteFile String
then callback(err, ServerCredentials server, ssh2.Client conn)
Source:

putFileSudo(server, localFile, remoteFile, then)

Uploads a file on the remote via sudo support
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
localFile String
remoteFile String
then callback(err, ServerCredentials server, ssh2.Client conn)
Source:

readFile(server, remoteFile, then)

Reads a file on the remote
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remoteFile String
then callback(err, ServerCredentials server, ssh2.Client conn)
Source:

readFileSudo(server, remoteFile, then)

Reads a file on the remote via sudo
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remoteFile String
then callback(err, ServerCredentials server, ssh2.Client conn)
Source:

rmdir(server, remotePath, then)

Deletes a file or directory rm -fr /some/path
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remotePath String
then callback(err, ServerCredentials server, ssh2.Client conn)
Source:

rmdirSudo(server, remotePath, then)

Deletes a file or directory sudo rm -fr /some/path
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remotePath String
then callback(err, ServerCredentials server, ssh2.Client conn)
Source:

run(server, cmd, doneEach, done)

Executes a command and return its stream, like of child_process.spawn. interactive also take care of - manage sudo cmd - log errors to output If cmd is an array, they are executed in serie, the pipe is open asap, you ll receive each stdout stderr data in serie
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
cmd String|[String]
doneEach callback(bool err, String stdout, String stderr, ServerCredentials server, ssh2.Client conn)
done callback(bool err, Stream stdout, Stream stderr, ServerCredentials server, ssh2.Client conn)
Source:

streamReadFile(server, remoteFile, then)

Reads a large file on the remote
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remoteFile String
then callback(err, Stream data, ServerCredentials server, ssh2.Client conn)
Source:

streamReadFileSudo(server, remoteFile, then)

Reads a large file on the remote via sudo
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remoteFile String
then callback(err, Stream data, ServerCredentials server, ssh2.Client conn)
Source:

writeFile(server, remoteFile, content, then)

Writes content to a remote file
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remoteFile String
content String
then callback(err, ServerCredentials server, ssh2.Client conn)
Source:

writeFileSudo(server, remoteFile, content, then)

Writes content to a remote file
Parameters:
Name Type Description
server ServerCredentials|ssh2.Client
remoteFile String
content String
then callback(err, ServerCredentials server, ssh2.Client conn)
Source: