2016-10-20 4 views
0

scpを使用して、あるサーバーから別のサーバーにファイルを送信するためにjcraftライブラリーを使用しています。コードは、私が使用して接続をclossingおりますのでこれはとてもsftp javaクライアントはsshdプロセスをリモートマシン上で実行し続けます

Scp scp=new Scp(); 

scp.setDestinationHost(CopyDestHost); 
scp.setDestinationPassword(CopyDestPassword); 
scp.setDestinationPublicKeyFile(CopyDestKey); 
scp.setDestinationUserName(CopyDestUser);    
scp.setSourceFile(temp.getAbsolutePath()); 
scp.setDestinationDirectory(filepath); 

stream.flush(); 
stream.close(); 
scp.send(); 

のように、新しいオブジェクトを作成して、それぞれが、何回か、他のJavaクラスから呼ばれているこの

public class Scp { 
String DestinationHost;//host IP 
String DestinationUserName;//username 
String DestinationPassword;//password 
String DestinationPublicKeyFile;//public key-if any 
String DestinationDirectory;//where to save on remote 
String SourceFile; 
/* 
    setters-getters 
    */ 
public void send() throws SftpException, FileNotFoundException, JSchException{ 
    JSch jsch = new JSch(); 
    Session session = null; 
    session = jsch.getSession(DestinationUserName,DestinationHost,22); 
    jsch.addIdentity(getDestinationPublicKeyFile(),getDestinationPassword()); 

    session.setConfig("StrictHostKeyChecking", "no"); 
    session.connect();  

    ChannelSftp channel = null; 

    //try to connect 
    channel = (ChannelSftp)session.openChannel("sftp"); 
    channel.connect(30000); 
    channel.connect(); 

    File localFile = new File(getSourceFile()); 
    File remoteFile=new File(getDestinationDirectory()); 
    channel.cd(remoteFile.getParent()); 

    channel.put(new FileInputStream(localFile),//the source file 
    remoteFile.getParentFile().getName());//the destination name(not the path) 

    channel.disconnect(); 
    session.disconnect(); 
    } 
} 

のようなものですchannel.disconnect();session.disconnect();なぜ接続が閉じられた後にリモートマシンのsshdプロセスの膨大なリストが実行されていますか?たとえば

root  13251 863 0 11:54 ?  00:00:00 sshd: skaros [priv] 
user  13300 13251 0 11:54 ?  00:00:00 sshd: [email protected] 
skaros 13301 13300 0 11:54 ?  00:00:00 /usr/lib/openssh/sftp-server 
root  14885 863 0 10:35 ?  00:00:00 sshd: skaros [priv] 
skaros 14986 14885 0 10:35 ?  00:00:00 sshd: [email protected] 
skaros 14987 14986 0 10:35 ?  00:00:00 /usr/lib/openssh/sftp-server 

これは問題ですか?私は手動でそれらを殺すべきですか?私はそれらをそのまま残していますか?

+0

ファイルのコピー中に例外がスローされますか? – Kenster

+0

@Kensterいくつか、時々。しかし、私はそれらが実行中のプロセスとして多くのものだとは思っていませんが、それについては確信できません –

+0

1)Javaプロセスを終了した後にリモートプロセスが消えますか? 2)スタンドアロンのSFTPクライアントを試しましたか?同じ動作をするか、リモートプロセスが正しく閉じられていますか? –

答えて

1

「バグ」であることが判明しました。 This postこれで解決しました

while (channel.getExitStatus() == -1){ 
     try{Thread.sleep(1000);}catch(Exception e){System.out.println(e);} 
    } 
関連する問題