sanketbajoria / ssh2-promise

ssh with promise/async await and typescript support
https://www.npmjs.com/package/ssh2-promise
MIT License
148 stars 25 forks source link

fastGet TypeError: cb is not a function #54

Closed jnandal closed 3 years ago

jnandal commented 4 years ago

Node V 12 & 14 Mac OSX ssh2-promise": "^0.1.7"

const SSH2Promise = require('ssh2-promise');
const main = async () => { 
    try { 
var sshconfig = {
    host: '***',
    username: '***',
    port: '***',
    password: '***',
    debug: (msg) => {
            console.log(msg);
    }}

  const ssh = new SSH2Promise(sshconfig);
  const ssh2 = await ssh.connect();
  const sftp = await ssh2.sftp();
  await sftp.fastGet('remotedir/test.zip', 'test.zip', {});
    } catch (e) {
        console.log(e);
    }
}

main();

Error: TypeError: cb is not a function at cbfinal (/Users/jnandal/z/jessica/sftp/node_modules/ssh2-streams/lib/sftp.js:1050:11) at SFTPStream._transform (/Users/jnandal/z/jessica/sftp/node_modules/ssh2-streams/lib/sftp.js:395:17) at SFTPStream.Transform._read (_stream_transform.js:191:10) at SFTPStream._read (/Users/jnandal/z/jessica/sftp/node_modules/ssh2-streams/lib/sftp.js:183:15) at SFTPStream.Transform._write (_stream_transform.js:179:12) at doWrite (_stream_writable.js:403:12) at writeOrBuffer (_stream_writable.js:387:5) at SFTPStream.Writable.write (_stream_writable.js:318:11) at Channel.ondata (_stream_readable.js:716:22) at Channel.emit (events.js:315:20)

Log:

[Arguments] { '0': 'ssh', '1': 'beforeconnect', '2': SSHConnection { _events: [Object: null prototype] { ssh: [Function: bound ], tunnel: [Function: bound ], 'ssh:disconnect': [Function: disconnectCb], 'ssh:continue': [Function: continueCb] }, _eventsCount: 4, _maxListeners: undefined, activeTunnels: {}, '$connectPromise': null, retries: 1, err: null, sftp: null, x11: null, sshConnection: null, config: { reconnect: true, port: '', reconnectTries: 10, reconnectDelay: 5000, host: '', username: '', password: '', debug: [Function: debug], uniqueId: '**' }, sshTunnels: [ [SSH2Promise] ],

}, '3': undefined } DEBUG: Local ident: 'SSH-2.0-ssh2js0.4.10' DEBUG: Client: Trying **** ... DEBUG: Client: Connected DEBUG: Parser: IN_INIT DEBUG: Parser: IN_GREETING DEBUG: Parser: IN_HEADER DEBUG: Remote ident: 'SSH-2.0-XFB.Gateway Unix' DEBUG: Outgoing: Writing KEXINIT DEBUG: Parser: IN_PACKETBEFORE (expecting 8) DEBUG: Parser: IN_PACKET DEBUG: Parser: pktLen:388,padLen:9,remainLen:384 DEBUG: Parser: IN_PACKETDATA DEBUG: Parser: IN_PACKETDATAAFTER, packet: KEXINIT DEBUG: Comparing KEXINITs ... DEBUG: (local) KEX algorithms: curve25519-sha256@libssh.org,curve25519-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha1 DEBUG: (remote) KEX algorithms: diffie-hellman-group1-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521 DEBUG: KEX algorithm: ecdh-sha2-nistp256 DEBUG: (local) Host key formats: ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa DEBUG: (remote) Host key formats: ssh-rsa DEBUG: Host key format: ssh-rsa DEBUG: (local) Client->Server ciphers: aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm,aes128-gcm@openssh.com,aes256-gcm,aes256-gcm@openssh.com DEBUG: (remote) Client->Server ciphers: aes256-ctr,aes128-ctr,aes128-cbc,3des-cbc,aes256-cbc DEBUG: Client->Server Cipher: aes128-ctr DEBUG: (local) Server->Client ciphers: aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm,aes128-gcm@openssh.com,aes256-gcm,aes256-gcm@openssh.com DEBUG: (remote) Server->Client ciphers: aes256-ctr,aes128-ctr,aes128-cbc,3des-cbc,aes256-cbc DEBUG: Server->Client Cipher: aes128-ctr DEBUG: (local) Client->Server HMAC algorithms: hmac-sha2-256,hmac-sha2-512,hmac-sha1 DEBUG: (remote) Client->Server HMAC algorithms: hmac-sha2-256,hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96 DEBUG: Client->Server HMAC algorithm: hmac-sha2-256 DEBUG: (local) Server->Client HMAC algorithms: hmac-sha2-256,hmac-sha2-512,hmac-sha1 DEBUG: (remote) Server->Client HMAC algorithms: hmac-sha2-256,hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96 DEBUG: Server->Client HMAC algorithm: hmac-sha2-256 DEBUG: (local) Client->Server compression algorithms: none,zlib@openssh.com,zlib DEBUG: (remote) Client->Server compression algorithms: none DEBUG: Client->Server compression algorithm: none DEBUG: (local) Server->Client compression algorithms: none,zlib@openssh.com,zlib DEBUG: (remote) Server->Client compression algorithms: none DEBUG: Server->Client compression algorithm: none DEBUG: Outgoing: Writing KEXECDH_INIT DEBUG: Parser: IN_PACKETBEFORE (expecting 8) DEBUG: Parser: IN_PACKET DEBUG: Parser: pktLen:380,padLen:7,remainLen:376 DEBUG: Parser: IN_PACKETDATA DEBUG: Parser: IN_PACKETDATAAFTER, packet: KEXECDH_REPLY DEBUG: Checking host key format DEBUG: Checking signature format DEBUG: Verifying host fingerprint DEBUG: Host accepted by default (no verification) DEBUG: Verifying signature DEBUG: Outgoing: Writing NEWKEYS DEBUG: Parser: IN_PACKETBEFORE (expecting 8) DEBUG: Parser: IN_PACKET DEBUG: Parser: pktLen:12,padLen:10,remainLen:8 DEBUG: Parser: IN_PACKETDATA DEBUG: Parser: IN_PACKETDATAAFTER, packet: NEWKEYS DEBUG: Outgoing: Writing SERVICE_REQUEST (ssh-userauth) DEBUG: Parser: IN_PACKETBEFORE (expecting 16) DEBUG: Parser: IN_PACKET DEBUG: Parser: Decrypting DEBUG: Parser: pktLen:28,padLen:10,remainLen:16 DEBUG: Parser: IN_PACKETDATA DEBUG: Parser: Decrypting DEBUG: Parser: HMAC size:32 DEBUG: Parser: IN_PACKETDATAVERIFY DEBUG: Parser: Verifying MAC DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC) DEBUG: Parser: IN_PACKETDATAAFTER, packet: SERVICE_ACCEPT DEBUG: Outgoing: Writing USERAUTH_REQUEST (none) DEBUG: Parser: IN_PACKETBEFORE (expecting 16) DEBUG: Parser: IN_PACKET DEBUG: Parser: Decrypting DEBUG: Parser: pktLen:28,padLen:13,remainLen:16 DEBUG: Parser: IN_PACKETDATA DEBUG: Parser: Decrypting DEBUG: Parser: HMAC size:32 DEBUG: Parser: IN_PACKETDATAVERIFY DEBUG: Parser: Verifying MAC DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC) DEBUG: Parser: IN_PACKETDATAAFTER, packet: USERAUTH_FAILURE DEBUG: Client: none auth failed DEBUG: Outgoing: Writing USERAUTH_REQUEST (password) DEBUG: Parser: IN_PACKETBEFORE (expecting 16) DEBUG: Parser: IN_PACKET DEBUG: Parser: Decrypting DEBUG: Parser: pktLen:12,padLen:10,remainLen:0 DEBUG: Parser: IN_PACKETDATA DEBUG: Parser: HMAC size:32 DEBUG: Parser: IN_PACKETDATAVERIFY DEBUG: Parser: Verifying MAC DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC) DEBUG: Parser: IN_PACKETDATAAFTER, packet: USERAUTH_SUCCESS [Arguments] { '0': 'ssh', '1': 'connect', '2': SSHConnection { _events: [Object: null prototype] { ssh: [Function: bound ], tunnel: [Function: bound ], 'ssh:disconnect': [Function: disconnectCb], 'ssh:continue': [Function: continueCb] }, _eventsCount: 4, _maxListeners: undefined, activeTunnels: {}, '$connectPromise': Promise { }, retries: 1, err: null, sftp: null, __x11: null, sshConnection: Client { _events: [Object: null prototype], _eventsCount: 6, _maxListeners: undefined, config: [Object], _readyTimeout: Timeout { _idleTimeout: -1, _idlePrev: null, _idleNext: null, _idleStart: 137, _onTimeout: null, _timerArgs: undefined, _repeat: null, _destroyed: true,

    [Symbol(asyncId)]: 5,
    [Symbol(triggerId)]: 1
  },
  _channels: {},
  _callbacks: [],
  _forwarding: {},
  _forwardingUnix: {},
  _acceptX11: 0,
  _agentFwdEnabled: false,
  _curChan: -1,
  _remoteVer: 'XFB.Gateway',
  _sshstream: [SSH2Stream],
  _sock: [Socket],
  _resetKA: [Function: resetKA],
  [Symbol(kCapture)]: false
},
config: {
  reconnect: true,

  reconnectTries: 10,
  reconnectDelay: 5000,
  host: '',
  username: '',
  password: '',
  debug: [Function: debug],
  uniqueId: ''
},
__sshTunnels: [ [SSH2Promise] ],
[Symbol(kCapture)]: false

}, '3': undefined } DEBUG: Parser: IN_PACKETBEFORE (expecting 16) [Arguments] { '0': 'ssh', '1': 'connect', '2': SSHConnection { _events: [Object: null prototype] { ssh: [Function: bound ], tunnel: [Function: bound ], 'ssh:disconnect': [Function: disconnectCb], 'ssh:continue': [Function: continueCb] }, _eventsCount: 4, _maxListeners: undefined, activeTunnels: {}, '$connectPromise': Promise { [Circular] }, retries: 0, err: null, sftp: null, __x11: null, sshConnection: Client { _events: [Object: null prototype], _eventsCount: 6, _maxListeners: undefined, config: [Object], _readyTimeout: Timeout { _idleTimeout: -1, _idlePrev: null, _idleNext: null, _idleStart: 137, _onTimeout: null, _timerArgs: undefined, _repeat: null, _destroyed: true,

    [Symbol(asyncId)]: 5,
    [Symbol(triggerId)]: 1
  },
  _channels: {},
  _callbacks: [],
  _forwarding: {},
  _forwardingUnix: {},
  _acceptX11: 0,
  _agentFwdEnabled: false,
  _curChan: -1,
  _remoteVer: 'XFB.Gateway',
  _sshstream: [SSH2Stream],
  _sock: [Socket],
  _resetKA: [Function: resetKA],
  [Symbol(kCapture)]: false
},
config: {
  reconnect: true,
  port: '',
  reconnectTries: 10,
  reconnectDelay: 5000,

},
__sshTunnels: [ [SSH2Promise] ],
[Symbol(kCapture)]: false

}, '3': undefined } DEBUG: Outgoing: Writing CHANNEL_OPEN (0, session) DEBUG: Parser: IN_PACKET DEBUG: Parser: Decrypting DEBUG: Parser: pktLen:28,padLen:10,remainLen:16 DEBUG: Parser: IN_PACKETDATA DEBUG: Parser: Decrypting DEBUG: Parser: HMAC size:32 DEBUG: Parser: IN_PACKETDATAVERIFY DEBUG: Parser: Verifying MAC DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC) DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_OPEN_CONFIRMATION DEBUG: Outgoing: Writing CHANNEL_REQUEST (929789, subsystem: sftp) DEBUG: Parser: IN_PACKETBEFORE (expecting 16) DEBUG: Parser: IN_PACKET DEBUG: Parser: Decrypting DEBUG: Parser: pktLen:12,padLen:6,remainLen:0 DEBUG: Parser: IN_PACKETDATA DEBUG: Parser: HMAC size:32 DEBUG: Parser: IN_PACKETDATAVERIFY DEBUG: Parser: Verifying MAC DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC) DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_SUCCESS (0) DEBUG: Parser: IN_PACKETBEFORE (expecting 16) DEBUG: Outgoing: Writing CHANNEL_DATA (929789) DEBUG: Parser: IN_PACKET DEBUG: Parser: Decrypting DEBUG: Parser: pktLen:28,padLen:9,remainLen:16 DEBUG: Parser: IN_PACKETDATA DEBUG: Parser: Decrypting DEBUG: Parser: HMAC size:32 DEBUG: Parser: IN_PACKETDATAVERIFY DEBUG: Parser: Verifying MAC DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC) DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_DATA (0) DEBUG: Parser: IN_PACKETBEFORE (expecting 16) DEBUG[SFTP]: Outgoing: Writing OPEN DEBUG: Outgoing: Writing CHANNEL_DATA (929789) DEBUG: Parser: IN_PACKET DEBUG: Parser: Decrypting DEBUG: Parser: pktLen:28,padLen:4,remainLen:16 DEBUG: Parser: IN_PACKETDATA DEBUG: Parser: Decrypting DEBUG: Parser: HMAC size:32 DEBUG: Parser: IN_PACKETDATAVERIFY DEBUG: Parser: Verifying MAC DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC) DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_DATA (0) DEBUG[SFTP]: Parser: Response: HANDLE DEBUG[SFTP]: Outgoing: Writing FSTAT DEBUG: Outgoing: Writing CHANNEL_DATA (929789) DEBUG: Parser: IN_PACKETBEFORE (expecting 16) DEBUG: Parser: IN_PACKET DEBUG: Parser: Decrypting DEBUG: Parser: pktLen:60,padLen:9,remainLen:48 DEBUG: Parser: IN_PACKETDATA DEBUG: Parser: Decrypting DEBUG: Parser: HMAC size:32 DEBUG: Parser: IN_PACKETDATAVERIFY DEBUG: Parser: Verifying MAC DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC) DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_DATA (0) DEBUG[SFTP]: Parser: Response: ATTRS DEBUG: Parser: IN_PACKETBEFORE (expecting 16) DEBUG[SFTP]: Outgoing: Writing CLOSE DEBUG: Outgoing: Writing CHANNEL_DATA (929789) DEBUG: Parser: IN_PACKET DEBUG: Parser: Decrypting DEBUG: Parser: pktLen:44,padLen:4,remainLen:32 DEBUG: Parser: IN_PACKETDATA DEBUG: Parser: Decrypting DEBUG: Parser: HMAC size:32 DEBUG: Parser: IN_PACKETDATAVERIFY DEBUG: Parser: Verifying MAC DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC) DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_DATA (0) DEBUG[SFTP]: Parser: Response: STATUS

/node_modules/ssh2-streams/lib/sftp.js:1044 cb(err); ^

TypeError: cb is not a function at cbfinal (sftp/node_modules/ssh2-streams/lib/sftp.js:1044:11) at SFTPStream._transform (/sftp/node_modules/ssh2-streams/lib/sftp.js:389:17) at SFTPStream.Transform._read (_stream_transform.js:191:10) at SFTPStream._read (/sftp/node_modules/ssh2-streams/lib/sftp.js:183:15) at SFTPStream.Transform._write (_stream_transform.js:179:12) at doWrite (_stream_writable.js:403:12) at writeOrBuffer (_stream_writable.js:387:5) at SFTPStream.Writable.write (_stream_writable.js:318:11) at Channel.ondata (_stream_readable.js:716:22) at Channel.emit (events.js:315:20)

If I define a call back, I creates a file with no data.

sanketbajoria commented 3 years ago

unable to reproduce this issue. Please see the file sftp-spec.js for more example