2014-01-23 1 views
0

코드를 작성해야합니다. 하나의 tar 파일을 sftp해야합니다. 유닉스 박스에서 다른 자바로. "SSHFACTORY"내가 모든 명령을 실행하지만, SFTP 명령을 실행할 수 없습니다 메신저 수 있어요을 사용 임 ... 하나는 제안하십시오 수 있습니다"scp"명령이나 java의 유닉스 명령을 사용하는 방법, 즉 하나의 유닉스 박스에서 다른 유닉스 박스로 파일을 sfp하는 방법.

String hostname,username,password; 
     System.out.println("Enter the machine to which you want to connect "); 
     hostname = br.readLine(); 
     System.out.println("Enter username : "); 
     username = br.readLine(); 
     System.out.println("Enter password : "); 
     password = br.readLine(); 
     SshParameters sshParams = new SshParameters(hostname,username, password); 
     SshSession session = new SshSession(sshParams); 
     session.setShellPrompt("$"); 
     session.connect(10000); 
     System.out.println("Login to websphe"); 
     session.send("sudo su - websphe"); 
     String contents = session.send("ls -ltr "); 
       session.send("directory u want the file to copy"); 
       session.send("scp [email protected]:"file u want to transfer" create.tar"); 

이 시점 그것을이 수도 실행할 // 수 없습니다 하나는 :)

답변

0

내가 서버 1에 SSH 키를 생성하여 경우에 고려할 것이라고 제안하고 .ssh/authorized_keys 파일을 서버 2에 추가하십시오 수 있습니다 passwrd

에 대한 프롬프트됩니다. 그렇게하면 비밀번호를 묻지 않습니다.

Here은 이에 대한 자습서입니다.