2013-06-23 2 views
2

나는 전송 파일을 위해 ssh 서버를 조롱하고 싶다. 그것을 위해 나는 아파치 미나 SSHD를 사용합니다. 시스템에서 전송 JSch 사용하십시오. 개인 키.아파치 SSHD & JSCH

JSch 클라이언트 코드.

JSch jSch = new JSch(); 
    jSch.addIdentity(privateKeyPath, passPhrase); 
    Session session = jSch.getSession(usernamePlans, remoteHost); 
    session.setHost(remoteHostPort); 
    config.setProperty("StrictHostKeyChecking", "no"); 
    session.setConfig(config); 
    session.setUserInfo(new StorageUserInfo(passPhrase)); 
    session.connect(); 

아파치 미나 SSHD 코드는

sshd = SshServer.setUpDefaultServer(); 
    sshd.setPort(22999); 

    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(privateKeyPath)); 
    sshd.setPasswordAuthenticator(new PasswordAuthenticator() { 

     public boolean authenticate(String username, String password, ServerSession session) { 
      // TODO Auto-generated method stub 
      return true; 
     } 
    }); 

    CommandFactory myCommandFactory = new CommandFactory() { 

     public Command createCommand(String command) { 
      System.out.println("Command: " + command); 
      return null; 
     } 
    }; 
    sshd.setCommandFactory(new ScpCommandFactory(myCommandFactory)); 

    List<NamedFactory<Command>> namedFactoryList = new ArrayList<>(); 

    namedFactoryList.add(new SftpSubsystem.Factory()); 
    sshd.setSubsystemFactories(namedFactoryList); 

    sshd.start(); 

아무도 나를 전송 파일에 대한 JSch 및 아파치 미나 SSHD를 연결 도와 드릴까요

?

스택 트레이스

com.jcraft.jsch.JSchException: java.net.SocketException: Invalid argument or cannot assign requested address 

Caused by: java.net.SocketException: Invalid argument or cannot assign requested address 
+0

전문가가 충분하지 않아도 코드 (또는 그러한 필요성)에 조롱을하는지 여부가 확실하지 않습니다. –

답변

0

당신은 포트를 설정() setHost를 호출하지 않아야합니다. 이 문서에 분명하게 언급되어 있습니다.

setHost 
public void setHost(String host) 

Sets the host to connect to. This is normally called by JSch.getSession(java.lang.String, java.lang.String), so there is no need to call it, if you don't want to change this host. This should be called before connect(). 

setPort 
public void setPort(int port) 
Sets the port on the server to connect to. This is normally called by JSch.getSession(java.lang.String, java.lang.String), so there is no need to call it, if you don't want to change the port. This should be called before connect(). 

대신 getSession()을 호출하는 동안 포트를 제공해야합니다. 아래 주어진 것으로

int port=22999; 
Session session = jsch.getSession(user, host, port);