jsch

How to Set Root Directory in Apache Mina Sshd Server in Java

僤鯓⒐⒋嵵緔 提交于 2019-11-29 01:53:19
I use Apache Mina Sshd API to start up a local SFTP server in java.In SFTP client i use Jcraft jsch API to create my SFTP client.I successfully start up a server.The problem is that i want to write some unit test cases to check whether client can put some files into server's root directory. Currently my SFTP server doesn't have any root directory.So i would like to know that is there is any approach to set server's root directory. Eg: C:\sftp How can i set this path as my server root directory.so then client can read and write files to it every time connect with the server.Thank you. public

“com.jcraft.jsch.JSchException: Auth fail” with working passwords

ε祈祈猫儿з 提交于 2019-11-29 00:45:29
问题 While trying to upload the file to our server, i am getting the following exception com.jcraft.jsch.JSchException: Auth fail at com.jcraft.jsch.Session.connect(Session.java:464) at com.jcraft.jsch.Session.connect(Session.java:158) at FtpService.transferFileToReciever(FtpService.java:80) at FtpService.transferFileToReciever(FtpService.java:54) at FtpService.transferFileToRecievers(FtpService.java:44) at FtpService.transferSingeFile(FtpService.java:241) at FtpService.main(FtpService.java:26)

com.jcraft.jsch.JSchException: Auth cancel

萝らか妹 提交于 2019-11-28 21:18:18
I'm trying to write an Ant script to retrieve an URL via port tunnelling. It works great when I use a password (the names xxxx'd out for privacy): <project default="main"> <target name="main"> <sshsession host="xxxx" username="xxxx" password="xxxx"> <LocalTunnel lport="1080" rhost="xxxx" rport="80"/> <sequential> <get src="http://localhost:1080/xxxx" dest="/tmp/xxxx"/> </sequential> </sshsession> </target> </project> But it doesn't work when I use a keyfile, like this: <sshsession host="xxxx" username="xxxx" keyfile="/Users/xxxx/.ssh/id_dsa" passphrase="xxxx"> <LocalTunnel lport="1080" rhost=

Sending commands to remote server through ssh by Java with JSch

那年仲夏 提交于 2019-11-28 20:47:09
I'm trying to set up a class so that I can ssh into a remote server (I have the IP, username, and password) and then send a command like "echo "test"" and then receive back the output (e.g., "test"). I'm using JSch to do this but I don't understand how to do it. import com.jcraft.jsch.*; public class ConnectSSH { public int execute (String command) { JSch jsch = new JSch(); String ip = "00.00.00.00; String user = "root"; String pass = "password"; int port = 22; try { Session session = jsch.getSession(user, ip, port); session.setPassword(pass); session.connect(); ... I'm not sure what to do, I

SFTP connection through Java asking for weird authentication

给你一囗甜甜゛ 提交于 2019-11-28 16:50:32
So I'm writing a little program that needs to connect to a remote server through SFTP, pull down a file, and then processes the file. I came across JSch through some answers here and it looked perfect for the task. So far, easy to use and I've got it working, with one minor thing I'd like to fix. I'm using the following code to connect and pull the file down: JSch jsch = new JSch(); Session session = null; try { session = jsch.getSession("username", "127.0.0.1", 22); session.setConfig("StrictHostKeyChecking", "no"); session.setPassword("password"); session.connect(); Channel channel = session

How do I load optional task sshexec into Ant in a no-configuration manner?

北城以北 提交于 2019-11-28 14:15:29
I am using sshexec, which depends on jsch-0.1.48.jar. I can't just put that into the ant/lib directory because other users wishing to use the same build script will have to make a configuration on their machine before they can do so. What I want to do is to be able to reference jsch-0.1.48.jar as part of the project. Currently, I have it sitting in project/libs directory and I am trying something like: <property name="lib" location="lib"/> <taskdef name="sshexec" classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec"> <classpath> <pathelement location="${lib}/jsch-0.1.48.jar"/> <

Using SFTP in Java, How do I transfer a file from one folder to another? [closed]

蓝咒 提交于 2019-11-28 13:14:08
I have a simple directory with two folders - In the SFTP_1 folder, I have a bitmap image. And the SFTP_2 folder is just an empty folder. Does Java have a native SFTP library to use? When I searched I only found a library online called JSch . How would I get started to run this example? Any tips appreciated, thanks! There's no native SFTP support in Java. The JSch library, you have found, is probably the most widely used SFTP implementation for Java. If you want to move the file from the SFTP_1 to the SFTP_2 using JSch, use the ChannelSftp.rename method : channelSftp.rename("/SFTP_1/file.txt",

Using JSch to SFTP when one must also switch user

青春壹個敷衍的年華 提交于 2019-11-28 13:09:03
I am using JSch in a Java client to connect to a remote server and get some files using SFTP. The following code has been working fine for me: - JSch ssh = new JSch(); JSch.setConfig(FileTransferConstants.STRICT_HOST_KEY_CHECKING, FileTransferConstants.NO); Session session = ssh.getSession(userName, host, port); session.setPassword(password); session.connect(); Channel channel = session.openChannel(FileTransferConstants.SFTP); channel.connect(); ChannelSftp sftp = (ChannelSftp) channel; sftp.cd(remoteDirectoryPath); sftp.lcd(localDirectoryPath); sftp.get(remoteDirectoryPath + remoteFileName,

JSch - How to issue commands as the user I have switched to

半城伤御伤魂 提交于 2019-11-28 13:07:58
I am using Jsch to remotely connect to a Linux server from Windows 7. I have to (i) login to Linux server with my credentials (ii) switch to root using a pmrun command [this is the procedure in our environment], and (iii) execute su command to switch as "someuser" (iv) execute further commands as that "someuser" I completed the steps (i) and (ii). After completing step (ii), the InputStream from the channel shows the command-prompt as that of the root user. So I assume that I have become the root user now. Now, do I need to get the root user's session to further execute an su command, or is

Remove of unwanted characters when I am using JSch to run command [duplicate]

随声附和 提交于 2019-11-28 13:02:00
This question already has an answer here: Getting unwanted characters when reading command output from SSH server using JSch 1 answer jsch = new JSch(); session = jsch.getSession(userName, ip, 22); session.setPassword(passWord); session.connect(); channel = session.openChannel("shell"); expect = new Expect(channel.getInputStream(), channel.getOutputStream()); ((ChannelShell) channel).setPtyType("dumb"); channel.connect(); System.out.println("After channel and expect"); if (expect.expect("#") > -1) { output = "Connected"; } else { output = "Unexpected Prompt"; System.out.println("Unexpected