title: Failure code 4 while uploading file to SFTP server using Node.js
body: <p>I have written code to establish a SFTP connection and transfer files to the SFTP server using Node.js <code>sftp.put</code> command. I'm getting the following error while transferring the file. I can establish the connection successfully. But I cannot read/write files to the server. I have attached the code below</p>
  <p>Code</p>
  <pre><code>let sftp = new client();
  
    let filename = &quot;sound.mp3&quot;;
    const filePath = path.join(__dirname, '../audio', filename)
    
     const putConfig = {
      flags: 'w', // w - write and a - append
      encoding: null, // use null for binary files
      mode: 0o666, // mode to use for created file (rwx)
      autoClose: true // automatically close the write stream when finished
    };
    
    sftp.connect({
        host: 'host',
        port: '22',
        username: 'xxxx',
        password: 'xxx'
      }).then(() =&gt; {
        return sftp.put(filePath, '/', putConfig)
      }).then(data =&gt; {
        console.log(data, 'the data info');
      }).catch(err =&gt; {
        console.log(err, 'catch error');
      });
  </code></pre>
  <p>Error</p>
  <pre class="lang-none prettyprint-override"><code>Error: put-&gt;put: Failure /data
      at fmtError (D:\project\node_modules\ssh2-sftp-client\src\utils.js:53:18)
      at SftpClient.put (D:\project\node_modules\ssh2-sftp-client\src\index.js:684:13)
      at processTicksAndRejections (internal/process/task_queues.js:93:5) {
    code: 4,
    custom: true
  }
  D:\project\node_modules\ssh2\lib\protocol\crypto\poly1305.js:20
  function J(a){if(b.onAbort)b.onAbort(a);L(a);O=!0;a=new WebAssembly.RuntimeError(&quot;abort(&quot;+a+&quot;). Build with -s ASSERTIONS=1 for more info.&quot;);r(a);throw a;}var V=&quot;data:application/octet-stream;base64,&quot;,W=&quot;data:application/octet-stream;base64,AGFzbQEAAAABIAZgAX8Bf2ADf39/AGABfwBgAABgAAF/YAZ/f39/f38AAgcBAWEBYQAAAwsKAAEDAQAAAgQFAgQFAXABAQEFBwEBgAKAgAIGCQF/AUGAjMACCwclCQFiAgABYwADAWQACQFlAAgBZgAHAWcABgFoAAUBaQAKAWoBAAqGTQpPAQJ/QYAIKAIAIgEgAEEDakF8cSICaiEAAkAgAkEAIAAgAU0bDQAgAD8AQRB0SwRAIAAQAEUNAQtBgAggADYCACABDwtBhAhBMDYCAEF/C4wFAg5+Cn8gACgCJCEUIAAoAiAhFSAAKAIcIREgACgCGCESIAAoAhQhEyACQRBPBEAgAC0ATEVBGHQhFyAAKAIEIhZBBWytIQ8gACgCCCIYQQVsrSENIAAoAgwiGUEFbK0hCyAAKAIQIhpBBWytIQkgADUCACEIIBqtIRAgGa0hDiAYrSEMIBatIQoDQCASIAEtAAMiEiABLQAEQQh0ciABLQAFQRB0ciABLQAGIhZBGHRyQQJ2Qf///x9xaq0iAyAOfiABLwAAIAEtAAJBEHRyIBNqIBJBGHRBgICAGHFqrSIEIBB+fCARIAEtAAdBCHQgFnIgAS0ACEEQdHIgAS0ACSIRQRh0ckEEdkH///8fcWqtIgUgDH58IAEtAApBCHQgEXIgAS0AC0EQdHIgAS0ADEEYdHJBBnY
  
  RuntimeError: abort(Error: put-&gt;put: Failure /data). Build with -s ASSERTIONS=1 for more info.
      at process.J (D:\project\node_modules\ssh2\lib\protocol\crypto\poly1305.js:20:53)
      at process.emit (events.js:210:5)
      at process.EventEmitter.emit (domain.js:475:20)
      at processPromiseRejections (internal/process/promises.js:201:33)
      at processTicksAndRejections (internal/process/task_queues.js:94:32)
  </code></pre>