Results 1 to 4 of 4
  1. #1
    sanaline is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default Java Programm for ssh connection

    dear user,

    i have a big problem. I have to write a programm in java but i don't really know how to start...
    i have to use:


    > Generated Documentation (Untitled) - für SSH
    >
    > cron4j - Documentation and manual - für cron-Jobs


    All input entered are transferred from the GUI program to a control program. This can also be carried out by time.

    The control program is also implemented in Java and the following responsibilities:

    Access to the specified (UNIX) computer via SSH.
    Starting a program on the computer servers .....> command line
    Communication of the current status of the GUI program

    Requirements:

    the GUI program and the control program installed on a defined Linux computer on which the user can log in from the local Windows computer.

    Communication:

    it will be possible that the Gui communicate program and the control program with each other and exchange data. Gui The program shall provide all data entered to the control program. This requires the control program from the GUI program can be started. Since this will work also delayed, the call shall be conducted with the necessary parameters via command line.

    The Delayed Start of the control program can LUNIX board means (...> cron-jobs done). Therefore, no special user rights.
    During a run can ask the program Gui its status by the control program and provide to the surface. The control program runs on after the user logs out the user from LUNIX computer.

    Best regards,

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Okay? And you are asking us for what? To start you need to open a text editor and start coding.

  3. #3
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    We don't hand out code here, so if that's what you're asking for then you're in the wrong place. However if you have a more specific question on theory or why your segment of code isn't working properly you can ask us.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  4. #4
    sanaline is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default

    i have already made the programm ...now wenn i give the command i can see the output but my problem is i want to start a programm and just see the result like programm has started, programm is running , programm has finished... and all of these notification, i want to see it on status...
    my question is how to start a programm with my java programm...what do i have to add to my programm??
    here the code i had already wrote...:

    SSH2Connect:
    Java Code:
    package p1;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.UnknownHostException;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Properties;
    
    import com.mindbright.ssh2.SSH2AuthKbdInteract;
    import com.mindbright.ssh2.SSH2AuthPassword;
    import com.mindbright.ssh2.SSH2Authenticator;
    import com.mindbright.ssh2.SSH2Connection;
    import com.mindbright.ssh2.SSH2ConsoleRemote;
    import com.mindbright.ssh2.SSH2Exception;
    import com.mindbright.ssh2.SSH2FatalException;
    import com.mindbright.ssh2.SSH2Transport;
    import com.mindbright.ssh2.SSH2UserAuth;
    
    
    public class SSH2Connect {
    
        protected SSH2Transport transport;
        protected SSH2Connection connection;
        protected SSH2UserAuth userAuth;
        private final Properties props = new Properties();
        SSH2Authenticator authenticator;
        private String output = "";
        List<String> texte = new ArrayList<String>();
    
    
    
        /**
         * Simple constructor to use for password authentication. This will actually
         * be able to use both the password and keyboard interactive authentication
         * protocols.
         * @param transport connected transport layer
         * @param username name of user
         * @param password password of user
         * @param timeout timeout in milliseconds for authentication phase (0 means
         *            no timeout)
         * @throws IOException
         * @throws UnknownHostException
         * @see SSH2Transport
         */
        public SSH2Connect(SSH2Transport transport, String user, String pass, long timeout,
                           String server, String command) throws SSH2Exception,
                                                   UnknownHostException,
                                                   IOException {
            props.put("servername", server);
            props.put("username", user);
            props.put("password", pass);
            props.put("auth-method", "password");
            authenticator = new SSH2Authenticator(user);
            authenticator.addModule(new SSH2AuthPassword(pass));
            authenticator.addModule(new SSH2AuthKbdInteract(pass));
            init(transport, authenticator, timeout);
       
             SSH2ConsoleRemote console = new SSH2ConsoleRemote(connection);
            console.command(command);
            BufferedReader in = new BufferedReader(new InputStreamReader(console.getStdOut())); 
            
            
            while ((output = in.readLine()) != null){
            
           
            
            texte.add(output);
            
            
            
            }
           
        }
        
        public List<String> getTexte() {
        	return texte;
        }
    
    
    
    
        private void init(SSH2Transport transport, SSH2Authenticator authenticator,
                          long authTimeout) throws SSH2Exception {
            this.transport = transport;
    
            transport.boot();
    
            if (!transport.waitForKEXComplete()) {
                throw new SSH2FatalException("Key exchange failed: "
                    + transport.getDisconnectMessage());
            }
    
            userAuth = new SSH2UserAuth(transport, authenticator);
            if (!userAuth.authenticateUser("ssh-connection", authTimeout)) {
                throw new SSH2FatalException("Permission denied");
            }
            
           
    
    
            connection = new SSH2Connection(userAuth, transport);
            transport.setConnection(connection);
            authenticator.clearSensitiveData();
    
            int alive = transport.getOurPreferences().getIntPreference("alive");
            transport.enableKeepAlive(alive);
        }
    
    
        public SSH2Transport getTransport() {
            return transport;
        }
    
    
        public SSH2Connection getConnection() {
            return connection;
        }
     
    
        public List <String> getOutput() {
            return texte;
            
        }
    
       
    
    
    
    }

    für GUI:

    Java Code:
    ......private void startActionPerformed(ActionEvent evt) {
    
            if (servername.getText().isEmpty() || user.getText().isEmpty()
                || passwrd.getPassword().length == 0) {
            	status.setText("Einträge fehlen...");
                status.setForeground(Color.red);
                status.repaint();
            } else {
    
    
                worker = new SwingWorker<String, Void>() {
    
                    List <String> message;
    
                    
                   
                    @Override
                    protected String doInBackground() throws Exception {
                    	status.setText("now trying to connect...");
                    	
                   
                        status.setForeground(Color.black);
    
    
                        SecureRandomAndPad secureRandom = new SecureRandomAndPad(
                            new SecureRandom());
    
                        transport = new SSH2Transport(new Socket(servername.getText(), 22),
                            secureRandom);
                        SSH2Connect ssh2 = new SSH2Connect(transport, user.getText(),
                            String.valueOf(passwrd.getPassword()), 100, servername.getText(),
                            pfad.getText());
                        
                        status.setText("connected successfully");
                        message = ssh2.getTexte();
                       return "";
                        
                    }
    
    
                    @Override
                    protected void done() {
                        // nach erfolgreicher conn muss hier was gemacht werden
                    	
                    	status.append("\n");
                    	for(String text : message) {
                    		status.append(text);
                    		status.append("\n");
                    		
                    	}
                    }
                };
                
                worker.execute();
    
            } // end else
        }//
    
    
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            EventQueue.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    try {
                        SSHGUI Testclient = new SSHGUI();
                        Testclient.setVisible(true);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    
        // Variables declaration - do not modify//GEN-BEGIN:variables
        private JLabel jLabel1;
        private JLabel jLabel2;
        private JLabel jLabel3;
        private JLabel jLabel4;
        private JLabel jLabel5;
        private JLabel jLabel6;
        private JPasswordField passwrd;
        private JScrollPane jScrollPane1;
        private JTextField pfad;
        private JTextField servername;
        private JButton start;
        private JTextField user;
        private JTextArea status;
        
        
        // End of variables declaration//GEN-END:variables
    
    
    
    }

Similar Threads

  1. How to create an executable from my java programm
    By Chaosje in forum New To Java
    Replies: 3
    Last Post: 05-12-2011, 03:32 PM
  2. Replies: 47
    Last Post: 01-09-2011, 08:53 PM
  3. Java.net.socket connection :connection closed
    By veeru541 in forum Advanced Java
    Replies: 2
    Last Post: 06-27-2010, 02:14 AM
  4. Help:Design programm in data structure in java
    By bosaod in forum New To Java
    Replies: 1
    Last Post: 05-09-2010, 12:38 PM
  5. Why my java lan game programm slow!
    By arnelpogs in forum Networking
    Replies: 2
    Last Post: 12-07-2009, 04:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •