node.jsexpressssh2-sftp-client

"multer-sftp": Permission denied when writting on remote sftp server


I am using multer-sftp to make a safe file upload. But when I try to write (upload) file to the server, I get weird error. Can someone help me to solve the issue ? I use "multer-sftp": "^1.1.1", "ssh2-sftp-client": "^7.1.0" and "express": "^4.17.1".

Logs


Solution

  • you have to configure user and group https://www.thegeekstuff.com/2012/03/chroot-sftp-setup/

    which you are using here in config of ssh2-sftp-client

    let commonOpts {
      host: 'localhost', // string Hostname or IP of server.
      port: 22, // Port number of the server.
      forceIPv4: false, // boolean (optional) Only connect via IPv4 address
      forceIPv6: false, // boolean (optional) Only connect via IPv6 address
      username: 'donald', // string Username for authentication.
      password: 'borsch', // string Password for password-based user authentication
      agent: process.env.SSH_AGENT, // string - Path to ssh-agent's UNIX socket
      privateKey: fs.readFileSync('/path/to/key'), // Buffer or string that contains
      passphrase: 'a pass phrase', // string - For an encrypted private key
      readyTimeout: 20000, // integer How long (in ms) to wait for the SSH handshake
      strictVendor: true // boolean - Performs a strict server vendor check
      debug: myDebug // function - Set this to a function that receives a single
                    // string argument to get detailed (local) debug information.
      retries: 2 // integer. Number of times to retry connecting
      retry_factor: 2 // integer. Time factor used to calculate time between retries
      retry_minTimeout: 2000 // integer. Minimum timeout between attempts
    };