Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jdcasey/sshwrap

Convenience API for Jsch
https://github.com/jdcasey/sshwrap

Last synced: about 1 month ago
JSON representation

Convenience API for Jsch

Awesome Lists containing this project

README

        

# SSHWrap - Convenience API for Jsch #

SSHWrap is designed to provide a minimal set of classes that allow you streamlined access to the features of the Jsch Java SSH client library.

## Usage ##

Imagine that you need to create and initialize a bare remote Git repository for a project you're about to push. The following method will do the trick:

private boolean createRemoteGitRepo( final String dir )
throws IOException, SSHWrapException
{
SSHConnection ssh = new SSHConnection( USER, HOST, PORT ).connect();

final Set cmds = new HashSet();
cmds.add( "mkdir -p " + dir );
cmds.add( "git --git-dir=" + dir + " --bare init" );

final ByteArrayOutputStream cmdOutput = new ByteArrayOutputStream();

for ( final String cmd : cmds )
{
cmdOutput.reset();
final int result = ssh.execute( cmd, cmdOutput );

if ( LOGGER.isDebugEnabled() )
{
LOGGER.debug( new String( cmdOutput.toByteArray() ) );
}

if ( result != 0 )
{
return false;
}
}

return true;
}