Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

532
Vistas
ssh2 nodejs | upload file to sftp | Error: Permission denied at 101

When trying to upload a file to sftp server permission denied error appears. The same operation works if file is transferred via FilezIlla.

const UploadFiletoFTP = () => {
      let Client = require('ssh2').Client;
      var connSettings = {
        host: 'abc.com',
        port: 22,
        username: 'user',
        password: 'pass',
      };

  var conn = new Client();
  conn
    .on('ready', function () {
      conn.sftp(function (err, sftp) {
        try {
          if (err) {
            console.log(err);
            throw 'error ' + err;
          }
          console.log('connected');
          var fs = require('fs'); // Use node filesystem
          var readStream = fs.createReadStream(
            require('path').join(
              __dirname +
                '/audio/test_data_25_05_2022_09_58_00.zip'
            )
          );

          sftp.readdir(
            'speech/non-english',
            function (err, list) {
              if (err) throw err;
              // List the directory in the console
              console.dir(list);
              // Do not forget to close the connection, otherwise you'll get troubles
              conn.end();
            }
          );

          var writeStream = sftp.createWriteStream('SpeechIQ', {
            flags: 'a', // w - write and a - append
            encoding: null, // use null for binary files
            mode: 0o666, // mode to use for created file (rwx)
          });

          writeStream.on('close', function () {
            console.log('- file transferred succesfully');
          });

          writeStream.on('end', function () {
            console.log('sftp connection closed');
            conn.end();
          });

          readStream.pipe(writeStream);
        } catch (err) {
          console.error(err);
        }
      });
    })
    .connect(connSettings);
};

UploadFiletoFTP();

When the above code is run below error appears:

events.js:377
      throw er; // Unhandled 'error' event
      ^

Error: Permission denied
    at 101
Emitted 'error' event on Client instance at:
.
.
.
.
  code: 3
}

Please advise if I am missing something.

Below snippet lists the files in the directory but the writestream is not working.

sftp.readdir(
            'speech/non-english',
            function (err, list) {
              if (err) throw err;
              // List the directory in the console
              console.dir(list);
              // Do not forget to close the connection, otherwise you'll get troubles
              conn.end();
            }
          );
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I had to give the filename to which the data has to be uploaded

var writeStream = sftp.createWriteStream('SpeechIQ/filename.zip', {
            flags: 'a', // w - write and a - append
            encoding: null, // use null for binary files
            mode: 0o666, // mode to use for created file (rwx)
          });
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda