sockets - com.jcraft.jsch.JSchException: java.net.ConnectException: Connection refused: connect -


i understand there duplicate >>> copied duplicate >>>as long local machine has ssh server running <<<<< cannot comment , cannot question (and im not providing answer....)

it stated "as long local machine has ssh server running" not know how have ssh server running. turn on putty (double click on it) (not sure if means ssh(?putty?) server (?) running... doubt so...

im new socket programming. making use of jsch (http://www.jcraft.com/jsch/) try connect remote server (later stage) currently, code use , im trying connect local computer , execute command (ls exact) test. however, keep hitting connection refused. googled , noticed there articles mentions on "having server listening" have no idea means. please view code below.

import java.awt.event.*;  import javax.swing.*;  import java.awt.*; import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstreamreader; import java.util.properties;  import com.jcraft.jsch.*;    class swingworkerexample {      jtextfield hostfield;     jtextfield usernamefield;     jtextfield passwordfield;     jpanel panel;       public swingworkerexample() {         jpanel p = panel = new jpanel(new gridlayout(0,2));         hostfield = new jtextfield(20);         usernamefield = new jtextfield(20);         passwordfield = new jpasswordfield(20);         jbutton testbutton = new jbutton("connect!");         testbutton.addactionlistener(new actionlistener() {                 public void actionperformed(actionevent ev) {                     testconnectionbuttonactionperformed(ev);                 }             });         p.add(new jlabel("host:"));         //127.0.0.1         p.add(hostfield);         p.add(new jlabel("user:"));         //mycomputerusername         p.add(usernamefield);         p.add(new jlabel("password:"));         //mycomputerpassword         p.add(passwordfield);         p.add(testbutton);     }      public jpanel getpanel() {         return panel;     }      private void testconnectionbuttonactionperformed(actionevent evt) {          swingworker sw = new swingworker(){                  protected object doinbackground() throws exception {                     try {                         jsch jsch = new jsch();                          string host = hostfield.gettext();                         string username = usernamefield.gettext();                         string password = passwordfield.gettext();                          session session = jsch.getsession(username, host);                         session.setpassword(password);                         session.setconfig("stricthostkeychecking", "no");                          session.settimeout(20000);                         system.out.println("connecting server...");                         session.connect();                          return session;                     }                     catch(exception ex) {                         ex.printstacktrace();                         throw ex;                     }                 }                  public void done(){                     try {                         system.out.println(get());                     } catch (exception ex) {                         ex.printstacktrace();                     }                 }             };          sw.execute();      }       public static void main(string[] egal) {         eventqueue.invokelater(new runnable(){public void run() {             swingworkerexample ex = new swingworkerexample();             jframe f = new jframe("bla");             f.setdefaultcloseoperation(windowconstants.dispose_on_close);             f.setcontentpane(ex.getpanel());             f.pack();             f.setvisible(true);         }});     }      public void remotels() throws jschexception, ioexception {         jsch js = new jsch();         session s = js.getsession("kellyseo", "192.168.0.103", 22);         s.setpassword("s9031808z");         properties config = new properties();         config.put("stricthostkeychecking", "no");         s.setconfig(config);         s.connect();          channel c = s.openchannel("exec");         channelexec ce = (channelexec) c;          ce.setcommand("ls -l");         ce.seterrstream(system.err);          ce.connect();          bufferedreader reader = new bufferedreader(new inputstreamreader(ce.getinputstream()));         string line;         while ((line = reader.readline()) != null) {           system.out.println(line);         }          ce.disconnect();         s.disconnect();          system.out.println("exit code: " + ce.getexitstatus());        }          public void remotemkdir() throws jschexception, ioexception {         jsch js = new jsch();         session s = js.getsession("myusername", "myremotemachine.mycompany.com", 22);         s.setpassword("mypassword");         properties config = new properties();         config.put("stricthostkeychecking", "no");         s.setconfig(config);         s.connect();          channel c = s.openchannel("exec");         channelexec ce = (channelexec) c;          ce.setcommand("mkdir remotetestdir");         ce.seterrstream(system.err);          ce.connect();          bufferedreader reader = new bufferedreader(new inputstreamreader(ce.getinputstream()));         string line;         while ((line = reader.readline()) != null) {           system.out.println(line);         }          ce.disconnect();         s.disconnect();          system.out.println("exit code: " + ce.getexitstatus());        }        public void remotecopy() throws jschexception, ioexception, sftpexception {         jsch js = new jsch();         session s = js.getsession("myusername", "myremotemachine.mycompany.com", 22);         s.setpassword("mypassword");         properties config = new properties();         config.put("stricthostkeychecking", "no");         s.setconfig(config);         s.connect();          channel c = s.openchannel("sftp");         channelsftp ce = (channelsftp) c;          ce.connect();          ce.put("/home/myuser/test.txt","test.txt");          ce.disconnect();         s.disconnect();           } } 

btw uses commandprompt ping 127.0.0.1 okay if use telnet 127.0.0.1 says not open connection host (i turned on putty(?double click?) , on port 23: connect failed. and, ssh = putty ... right? (i cannot use 'ssh' command in command prompt)

links: 1) http://sourceforge.net/p/jsch/mailman/message/31745775/

and 2) http://javarevisited.blogspot.sg/2013/02/java-net-connectexception-connection-refused.html

and 3) http://www.jcraft.com/jsch/examples/ , 4) run command on ssh jsch , 5) can use jsch ssh key-based communication?

and... advance!!

oh, , theres http://www.ganymed.ethz.ch/ssh2/ (an alternative jsch.. advise welcomed!) when try run example, says no main. which.. duno >.< stick w jsch till then....

btw, try https://serverfault.com/questions/185153/free-public-ssh-server-for-testing-purposes server but... have no idea whats address, username , password. (i have http://sdf.org account newly created when try connect it, says unknownhost. fyi!)

forgot mention, im using windows 7 , 'yum' not command in command prompt...

you're attempting connect local host via ssh protocol. jsch isn't socket programming, issue related socket programming.

essentially issue program trying connect port isn't open, in instance it's port 22. don't have ssh server ssh client can't anything. you're making telephone call doesn't have phone.

to resolve issue need either find test server have ssh running on development against or install ssh server on local pc. windows box best bet cygwin, allow emulate posix system , run sshd on local machine. google search cygwin , sshd provide examples of how set up.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -