Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a java program using jsch which will connect to one unix server and display the number of files in it. Now I need to connect to another unix server and copy one file from it to first server.

code below package unix;

import; import; import; import java.util.Vector; import com.jcraft.jsch.Channel; import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; import com.jcraft.jsch.SftpException;

public class DemoSftp {

public static void main(String[] args) throws JSchException, SftpException, IOException {

    String hostname = "hostname";
    String login = "login";
    String password = "password";
    String directory = "x/y/z";

    java.util.Properties config = new java.util.Properties();
    config.put("StrictHostKeyChecking", "no");

    JSch ssh = new JSch();
    Session session = ssh.getSession(login, hostname, 22);

    Channel channel = session.openChannel("sftp");
    ChannelSftp sftp = (ChannelSftp) channel;;
    Vector files ="*");
    System.out.printf("Found %d files in dir %s%n", files.size(), directory);



in second server also, I need to give user name and password. Could you please help me?

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.