I am trying to use local host as a SLTP server. I am using Java's JSC library to implement SFTP with SSH2. The following code uploads a text file to a directory on the local machine with sftp but I can not connect to the local host.
Import java.io.BuffferedInputStream; Import java.io.buffferedOutputStream; Import java.io.file; Import java.io.FileInputStream; Import java.io.FileOutputStream; Import java.io.OutputStream; Import com.jcraft.jsch.Channel; Import com.jcraft.jsch.ChannelSftp; Import com.jcraft.jsch.JSch; Import com.jcraft.jsch.Session; Public class server {public server} () public static zero main (string [] args) {string sftpohst = "localhost"; Int Sftpf = 22; String SFTPUSER = "root"; String SFTPPASS = ""; String SFTPWORKINGDIR = "D: \\ Upload"; Session session = null; Channel channel = null; ChannelSftp Channel SFTP = Faucet; Try {JSch jsch = new JSch (); Session = JSCJet session (SFTPUSER, SFTPHST, SFTPAP); Session.setPassword (SFTPPASS); Java.util.Properties config = new java.util.Properties (); Config.put ("hardhostky checking", "no"); Session.setConfig (config); Session.connect (); Channel = session Open channel ("SFTP"); Channel.connect (); ChannelSftp = (ChannelSftp) channel; ChannelSftp.cd (SFTPWORKINGDIR); File f = new file ("trial.txt"); ChannelSftp.put (new FileInputStream (f), f.getName ()); } Hold (Exception pre) {ex.printStackTrace (); }}}}
"Connection refused" means that there is no process to listen on the connection to the IP address and port that you In this situation, the most likely explanation is that your SSH server process is not running, or perhaps it is configured to listen on another port compared to port 22.
It seems that this is a Windows system? If this is the case, then you can see the Task Manager to see if there is a copy of the
sshd
program running to see if something is listening on port 22, a command line Open the window and runnetstat -an
. Then look for a line like this:< P> IfTCP 0.0.0.0.2 0.0.0.0: 06.0.0.0 LISTENING ^^ - Listen to port 22
sshd
is not running, it needs to be started. If this is going on, but nothing is listening on port 22, then you should check the configuration file of sshd.If you need further assistance in starting sshd, you should ask.
Comments
Post a Comment