Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ssh;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.InetAddress;
- import java.util.concurrent.TimeUnit;
- import net.schmizz.sshj.SSHClient;
- import net.schmizz.sshj.common.IOUtils;
- import net.schmizz.sshj.connection.channel.direct.Session;
- import net.schmizz.sshj.connection.channel.direct.Session.Command;
- public class ssh {
- static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- static sshCredential login;
- public static void main(String[] args) throws IOException {
- SSHClient ssh = new SSHClient();
- sshGUI gui = new sshGUI(ssh);
- gui.setupLoginUI();
- System.out.println("Port: " + login.port + "| IP: " + login.ip.toString() + "| Username: " + login.username + "| PasswordLength: " + login.password.length() + "| HostKey: " + login.HostKey );
- InetAddress ip = InetAddress.getByName("127.0.0.1");
- int port = 22;
- String username = "", password = "";
- String base = "";
- String[] tempvars;
- // -
- base = queryInput("ssh> ");
- tempvars = base.split("@");
- username = tempvars[0];
- tempvars = tempvars[1].split(":");
- ip = InetAddress.getByName(tempvars[0]);
- port = Integer.parseInt(tempvars[1]);
- password = queryInput("Password? (Leave blank for none)> ");
- ssh.addHostKeyVerifier("");
- ssh.connect(ip, port);
- ssh.authPassword(username, password);
- final Session session = ssh.startSession();
- try {
- final Command cmd = session.exec("echo test > ssh.test");
- System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
- cmd.join(5, TimeUnit.SECONDS);
- System.out.println("\n\n Exit stat: " + cmd.getExitStatus());
- } finally {
- session.close();
- }
- ssh.disconnect();
- }
- public static String queryInput(String text) {
- try {
- System.out.println(text);
- return br.readLine();
- } catch (Exception e) {
- System.out.println(e.getMessage() + "\n" + e.getStackTrace());
- return null;
- }
- }
- }
Add Comment
Please, Sign In to add comment