2016-04-29 12 views
1

mscdexでnodejs ssh2ライブラリを使用すると、sshサーバディレクトリの内容をリストし、特定のファイルを検索してダウンロードするsftp "フェッチ"ノードスクリプトがあります。スクリプトが "sftp.fastGet"を呼び出すダウンロードステップに到達すると、fastGetに提供されるコールバックは決して呼び出されません。NodeJS ssh2 fastgetは圧縮解除時に応答します

ssh接続オプションで「DEBUG」設定を有効にしました。 sftp.fastGetが実行されているようですが、「解凍」ステップに掛かっています。これは私が得ている出力です:

... 
DEBUG: Parser: Verifying MAC 
DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC) 
DEBUG: Parser: Decompressing 
// hangs here forever (or until timeout)... 

さらに奇妙なことに、いくつかのパケットが来て正しく復元されるようです。私は開いて割れて

info: Fetching xxx from /xxx/xxx/xxx to X:\xxx\xxx\xxx 
debug: DEBUG[SFTP]: Outgoing: Writing OPEN 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG: Parser: IN_PACKET 
debug: DEBUG: Parser: Decrypting 
debug: DEBUG: Parser: pktLen:20,padLen:5,remainLen:16 
debug: DEBUG: Parser: IN_PACKETDATA 
debug: DEBUG: Parser: Decrypting 
debug: DEBUG: Parser: HMAC size:20 
debug: DEBUG: Parser: IN_PACKETDATAVERIFY 
debug: DEBUG: Parser: Verifying MAC 
debug: DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC) 
debug: DEBUG: Parser: Decompressing 
// doesn't seem to hang here 
debug: DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Parser: Response: HANDLE 
debug: DEBUG[SFTP]: Outgoing: Writing FSTAT 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG: Parser: IN_PACKETBEFORE (expecting 8) 
debug: DEBUG: Parser: IN_PACKET 
debug: DEBUG: Parser: Decrypting 
debug: DEBUG: Parser: pktLen:28,padLen:10,remainLen:24 
debug: DEBUG: Parser: IN_PACKETDATA 
debug: DEBUG: Parser: Decrypting 
debug: DEBUG: Parser: HMAC size:20 
debug: DEBUG: Parser: IN_PACKETDATAVERIFY 
debug: DEBUG: Parser: Verifying MAC 
debug: DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC) 
debug: DEBUG: Parser: Decompressing 
// doesn't seem to hang here 
debug: DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Parser: Response: ATTRS 
debug: DEBUG: Parser: IN_PACKETBEFORE (expecting 8) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG[SFTP]: Outgoing: Writing READ 
debug: DEBUG: Outgoing: Writing CHANNEL_DATA (0) 
debug: DEBUG: Parser: IN_PACKET 
debug: DEBUG: Parser: Decrypting 
debug: DEBUG: Parser: pktLen:2388,padLen:6,remainLen:2384 
debug: DEBUG: Parser: IN_PACKETDATA 
debug: DEBUG: Parser: Decrypting 
debug: DEBUG: Parser: HMAC size:20 
debug: DEBUG: Parser: IN_PACKETDATAVERIFY 
debug: DEBUG: Parser: Verifying MAC 
debug: DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC) 
debug: DEBUG: Parser: Decompressing 
// hangs here forever... 

「[私のプロジェクト] \ node_modules \ SSH2ストリーム\ libに\ ssh.js」と「decompress.instance.flush」メソッドコールバックことがわかった。ここでは(より詳細な)デバッグです毎回呼ばれていませんでした。

ssh.js line 544: ... 
} else if (instate.status === IN_PACKETDATAAFTER) { 
    if (decompress.instance) { 
    if (!decomp) { 
    debug('DEBUG: Parser: Decompressing'); 
    decompress.instance.write(instate.payload); 
    // this function executes and calls the method below 
    decompress.instance.flush(Z_PARTIAL_FLUSH, function(){ 
     // this callback function is called during the first two iterations, 
     // but is not called the last time, when the process hangs 
     instate.payload = decompress.instance.read(); 
     var nextSlice; 
     if (i === chlen) 
     nextSlice = EMPTY_BUFFER; 
     else 
     nextSlice = chunk.slice(i); 
     self._transform(nextSlice, encoding, callback, true); 
    }); 
    return; 
    } else { 
    ... 

...そしてもちろん、ここで flush()コールバックは一度だけ呼び出され、すべての(現在の)非圧縮データをzlibのストリームから読み込まれ、私は

var sshClient = require('ssh2').Client; 

var client = new sshClient(); 

client.on('ready',()=> { 

    client.sftp((sftpErr, sftp) => { 

    sftp.readdir(remotepath, (dirErr, files) => { 

     var validFiles = files.filter((file) => { 
     return file.filename.match(regex); 
     }); 

     async.eachSeries(validFiles, (ftpFile, cb) => { 

     var remote = remotepath + ftpFile.filename; 
     var local = path.join(localpath, ftpFile.filename); 


     console.log('Fetching ' + ftpFile.filename + ' from ' + remote + ' to ' + local); 

     sftp.fastGet(remote, local, (getErr) => { 
      console.log('Fast Get Complete'); 
      // this is never called 
     }); 

     }); 

    }) 

    }); 

}); 

client.connect({ 
    host: "xxx.xxx.xxx.xxx", 
    port: 22, 
    username: "someuser", 
    password: "somepass", 
    debug: console.log, 
    algorithms: { 
    key: [ 
     "diffie-hellman-group1-sha1", 
    ], 
    cipher: [ 
     "blowfish-cbc", 
     "3des-cbc" 
    ], 
    compress: [ 
     "zlib" 
    ], 
    hmac: [ 
     "hmac-sha1", 
     "hmac-md5" 
    ] 
    } 
}); 

答えて

0

実行しているコードです。これは、圧縮されていないデータの長さがzlibストリームのhighWaterMarkを超えた場合にのみ問題でした。これは、mscdex/[email protected]の時点で修正されるはずです。

+0

これはすべてを解決しました。どうもありがとうございます! – BitReiver

関連する問題