Questions tagged [jsch]

JSch is a pure Java implementation of SSH2. JSch allows you to connect to an SSH server and use port forwarding, X11 forwarding, file transfer, etc., and you can integrate its functionality into your own Java programs.

JSch is a pure Java implementation of SSH2. JSch allows you to connect to an SSH server and use port forwarding, X11 forwarding, file transfer, etc., and you can integrate its functionality into your own Java programs.

Why JSch?

Originally, our motivation to develop this stuff is to allow users of our pure java X servers, WiredX, to enjoy secure X sessions. So, our efforts had mostly targeted to implement the SSH2 protocol for X11 forwarding. Of course, however, we are now also interested in adding other functionality like port forward, file transfer, terminal emulation, etc.

Features:

  • JSch is in pure Java, but it depends on Java Cryptography Extension (JCE). JSch is know to work with:
  • SSH2 protocol support.
  • Key exchange: diffie-hellman-group-exchange-sha1, diffie-hellman-group1-sha1
  • Cipher: blowfish-cbc, 3des-cbc, aes128-cbc, aes192-cbc, aes256-cbc, aes128-ctr, aes192-ctr, aes256-ctr, 3des-ctr, arcfour, arcfour128, arcfour256
  • MAC: hmac-md5, hmac-sha1, hmac-md5-96, hmac-sha1-96
  • Host key type: ssh-dss, ssh-rsa
  • Userauth: password
  • Userauth: publickey (DSA, RSA)
  • Userauth: keyboard-interactive
  • Userauth: gss-api-with-mic
  • X11 forwarding
  • xauth spoofing
  • connection through HTTP proxy.
  • connection through SOCKS5 proxy.
  • port forwarding.
  • stream forwarding.
  • signal sending.
  • environment variable passing.
  • remote exec.
  • generating DSA and RSA key pairs.
  • changing the passphrase for a private key.
  • partial authentication
  • SSH File Transfer Protocol(version 0, 1, 2, 3)
  • packet compression: zlib, zlib@openssh.com JZlib has been used.
  • hashed known_hosts file.
  • NONE Cipher switching. High Performance Enabled SSH/SCP supports NONE Cipher switching. Refer to ScpToNoneCipher.java.
  • JSch is licensed under BSD style license.

Official Website: http://www.jcraft.com/jsch/

Useful Links:

1673 questions
30
votes
3 answers

SFTP file transfer using Java JSch

Here is my code, which retrieves content of the file, on the remote server and display as output. package sshexample; import com.jcraft.jsch.*; import java.io.*; public class SSHexample { public static void main(String[] args) { String user…
MAHI
  • 9,263
  • 11
  • 36
  • 47
27
votes
10 answers

Sending commands to server via JSch shell channel

I can't figure it out how I can send commands via JSch shell channel. I do this, but it doesn't work: JSch shell = new JSch(); String command = "cd home/s/src"; Session session = shell.getSession(username, host, port); MyUserInfo ui = new…
Nezzit
  • 287
  • 1
  • 3
  • 7
24
votes
2 answers

Skipping Kerberos authentication prompts with JSch

I am using the Connect() method in the Ssh Java class below in order to connect to a server using SSH (JSch) and running a command in the server. The problem is that when running Connect() the server prompts the next messages: Kerberos username…
Haritz
  • 1,702
  • 7
  • 31
  • 50
24
votes
4 answers

Use JSch to put a file to the remote directory and if the directory does not exist, then create it

I would like to copy a file to the remote directory using Jsch library and SFTP protocol. If the directory on the remote host does not exist, then create it. In the API doc, http://epaul.github.com/jsch-documentation/javadoc/, I noticed in the put…
woraphol.j
  • 1,301
  • 5
  • 14
  • 22
23
votes
2 answers

Using JSch ChannelSftp: How to read multiple files with dynamic names?

I have to read a bunch of .CSV files with dynamic file names from a SFTP server. These files get generated every 15 minutes. I am using JSch's ChannelSftp, but there is no method which would give the exact filenames. I only see an .ls() method. This…
pingu
  • 645
  • 3
  • 11
  • 21
22
votes
3 answers

How to resolve Java UnknownHostKey, while using JSch SFTP library?

I'm running a java program where I transfer a file from one folder to another, using Java SFTP. The problem I'm having is that I'm getting the following error in my Java SFTP (using JSch)…
Caffeinated
  • 11,982
  • 40
  • 122
  • 216
22
votes
1 answer

Any way to disable known host checking with JSch?

I am trying to kick the tires of JSch and SSH connect to remote (Solaris) host from Java locally. I normally use PuTTy, which gives me a prompt about an unknown host every time I connect somewhere for the first time, then I say yes and it no longer…
amphibient
  • 29,770
  • 54
  • 146
  • 240
21
votes
6 answers

com.jcraft.jsch.JSchException: Auth cancel

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):
Dan Fabulich
  • 37,506
  • 41
  • 139
  • 175
21
votes
2 answers

How can convert inputstream to InputStreamsource or Datasource to attach in Spring JavaMail

I am getting inputstream from the Jsch channelSFTP like below. ChannelSftp channelSftp = (ChannelSftp) channel; InputStream input = channelsftp.get(unixPath); // unixPath is path to my file which is on SFTP server I have to attach the file in…
SRy
  • 2,901
  • 8
  • 36
  • 57
20
votes
1 answer

SFTP upload file Permission denied

I'm trying to upload excel file using SFTP to linux machine from my local windows PC. Here is my code: private void uploadToSftp() { try { ChannelSftp sftpClient = null; Channel channel = null; …
user9219740
20
votes
1 answer

Java SFTP upload using JSch, but how to overwrite the current file?

I am trying to upload two files to a server with SFTP using JSch. It works fine to upload the files if the directory is empty but I want to upload the same file over and over (just changing an id inside) but I can't figure out how to do this. There…
Sebastian L
  • 924
  • 2
  • 10
  • 20
20
votes
3 answers

JSch: How to keep the session alive and up

I'm writing Java GUI program for static route management using SSH. My code is as follows: import com.jcraft.jsch.*; import java.io.*; public class Konsep { String status; static String username; static String hostname; String…
user2277956
  • 201
  • 1
  • 2
  • 3
20
votes
3 answers

Simple SSH connect with JSch

I am trying to make something from this simple example : SSH, execute remote commands with Android I just want to see if I can connect from my android phone to a linux server using SSH but it doesn't work... Here is my main code : package…
Pozinux
  • 964
  • 2
  • 10
  • 22
18
votes
4 answers

How do I transfer a file from one directory to another using Java SFTP Library JSch?

I need to program a file transfer using JSch library. 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. My goal is to transfer the image using SFTP from…
Caffeinated
  • 11,982
  • 40
  • 122
  • 216
18
votes
5 answers

SFTP via JSch is throwing error 4: Failure

I am facing a peculiar issue while trying to SFTP a file from Windows to Unix server. The error "stack trace" is - 4: Failure at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846) at…
Saikat
  • 14,222
  • 20
  • 104
  • 125