java - Connection refused in sftp server -
java - Connection refused in sftp server -
i trying utilize localhost sftp server. i'm using jsch library of java implement sftp ssh2. next code upload text file directory on local machine sftp. cannot connect localhost.
import java.io.bufferedinputstream; import java.io.bufferedoutputstream; 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 void main(string[] args) { string sftphost = "localhost"; int sftpport = 22; string sftpuser = "root"; string sftppass =""; string sftpworkingdir = "d:\\upload"; session session = null; channel channel = null; channelsftp channelsftp = null; try{ jsch jsch = new jsch(); session = jsch.getsession(sftpuser,sftphost,sftpport); session.setpassword(sftppass); java.util.properties config = new java.util.properties(); config.put("stricthostkeychecking", "no"); session.setconfig(config); session.connect(); channel = session.openchannel("sftp"); channel.connect(); channelsftp = (channelsftp)channel; channelsftp.cd(sftpworkingdir); file f = new file("trial.txt"); channelsftp.put(new fileinputstream(f), f.getname()); }catch(exception ex){ ex.printstacktrace(); } } }
"connection refused" means there no process listening connections @ ip address , port you're trying connect to. in case, explanation ssh server process isn't running, or perhaps has been configured hear on other port port 22.
it looks windows system? if that's case, check task manager see if there re-create of sshd
programme running. see if listening on port 22, open command-line window , run netstat -an
. line this:
tcp 0.0.0.0:22 0.0.0.0:0 listening ^^-- listening on port 22
if sshd
isn't running, needs started. if running, nil listening on port 22, should examine sshd's configuration file.
if need farther help starting sshd, should inquire on http://superuser.com/.
java sftp jsch libssh2
Comments
Post a Comment