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T,8BAA8B,IAC9B,QACA,UAAU,SAGd,OAAO,KAAK,OAAO,EAAS,EAC9B,CAAE,MAAO,GACP,MAAM,EAAI,OAAS,EAAM,KAAK,SAAS,EAAK,QAC9C,CAAE,QACA,oBAAoB,KAAM,EAAW,SACrC,KAAK,kBACP,CACF,CAQA,GAAA,GACE,IAAI,EAAiB,EACrB,OAAO,IAAI,SAAQ,CAAC,EAAS,KAC3B,EAAY,iBAAiB,KAAM,MAAO,GAC1C,KAAK,WAAY,EACjB,EAAkB,KAChB,KAAK,UAAO,EACZ,KAAK,SAAS,0BACd,GAAQ,EAAK,EAEf,KAAK,GAAG,QAAS,GACb,KAAK,MACP,KAAK,SAAS,+BACd,KAAK,OAAO,QAGZ,KAAK,SAAS,yCACd,GAAQ,GACV,IACC,SAAQ,KACT,oBAAoB,KAAM,EAAW,OACrC,KAAK,eAAe,QAAS,GAC7B,KAAK,kBAAkB,GAE3B,EAGF,OAAO,QAAU","file":"/npm/ssh2-sftp-client@12.1.1/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/ssh2-sftp-client@12.1.1/src/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\nconst { Client } = require('ssh2');\nconst fs = require('node:fs');\nconst concat = require('concat-stream');\nconst { join, parse } = require('node:path');\nconst {\n  globalListener,\n  addTempListeners,\n  removeTempListeners,\n  haveConnection,\n  normalizeRemotePath,\n  localExists,\n  haveLocalAccess,\n  haveLocalCreate,\n  partition,\n} = require('./utils');\nconst { errorCode } = require('./constants');\n\nclass SftpClient {\n  constructor(\n    clientName = 'sftp',\n    callbacks = {\n      error: (err) => console.error(`Global error listener: ${err.message}`),\n      end: () => console.log('Global end listener: end event raised'),\n      close: () => console.log('Global close listener: close event raised'),\n    },\n  ) {\n    this.version = '12.0.1';\n    this.client = new Client();\n    this.sftp = undefined;\n    this.clientName = clientName;\n    this.endCalled = false;\n    this.errorHandled = false;\n    this.closeHandled = false;\n    this.endHandled = false;\n    this.remotePlatform = 'unix';\n    this.debug = undefined;\n    this.promiseLimit = 10;\n    this.eventCallbacks = callbacks;\n    this.client.on('close', globalListener(this, 'close', this.eventCallbacks));\n    this.client.on('end', globalListener(this, 'end', this.eventCallbacks));\n    this.client.on('error', globalListener(this, 'error', this.eventCallbacks));\n  }\n\n  debugMsg(msg, obj) {\n    if (this.debug) {\n      if (obj) {\n        this.debug(\n          `CLIENT[${this.clientName}]: ${msg} ${JSON.stringify(obj, null, ' ')}`,\n        );\n      } else {\n        this.debug(`CLIENT[${this.clientName}]: ${msg}`);\n      }\n    }\n  }\n\n  fmtError(err, name = 'sftp', eCode, retryCount) {\n    let msg = '';\n    let code = '';\n\n    if (err === undefined) {\n      msg = `${name}: Undefined error - probably a bug!`;\n      code = errorCode.generic;\n    } else if (typeof err === 'string') {\n      msg = `${name}: ${err}`;\n      code = eCode || errorCode.generic;\n    } else if (err.custom) {\n      msg = `${name}->${err.message}`;\n      code = err.code;\n    } else {\n      switch (err.code) {\n        case 'ENOTFOUND': {\n          msg = `${name}: Address lookup failed for host`;\n          break;\n        }\n        case 'ECONNREFUSED': {\n          msg = `${name}: Remote host refused connection`;\n          break;\n        }\n        case 'ECONNRESET': {\n          msg = `${name}: Remote host has reset the connection: ${err.message}`;\n          break;\n        }\n        default: {\n          msg = `${name}: ${err.message}`;\n        }\n      }\n      code = err.code || errorCode.generic;\n    }\n    const newError = new Error(msg);\n    newError.code = code;\n    newError.custom = true;\n    this.debugMsg(`${newError.message} (${newError.code})`);\n    return newError;\n  }\n\n  /**\n   * Add a listner to the client object. This is rarely necessary and can be\n   * the source of errors. It is the client's responsibility to remove the\n   * listeners when no longer required. Failure to do so can result in memory\n   * leaks.\n   *\n   * @param {string} eventType - one of the supported event types\n   * @param {function} callback - function called when event triggers\n   */\n  on(eventType, callback) {\n    this.client.prependListener(eventType, callback);\n  }\n\n  removeListener(eventType, callback) {\n    this.client.removeListener(eventType, callback);\n  }\n\n  _resetEventFlags() {\n    this.closeHandled = false;\n    this.endHandled = false;\n    this.errorHandled = false;\n  }\n\n  /**\n   *\n   * Create a new SFTP connection to a remote SFTP server.\n   * The connection options are the same as those offered\n   * by the underlying SSH2 module.\n   *\n   * @param {Object} config - an SFTP configuration object\n   *\n   * @return {Promise<Object>} which will resolve to an sftp client object\n   */\n  connect(config) {\n    let doReady, listeners;\n    return new Promise((resolve, reject) => {\n      listeners = addTempListeners(this, 'getConnection', reject);\n      if (config.debug) {\n        this.debug = config.debug;\n        this.debugMsg('connect: Debugging turned on');\n        this.debugMsg(`ssh2-sftp-client Version: ${this.version} `, process.versions);\n      }\n      this.promiseLimit = config.promiseLimit ?? 10;\n\n      doReady = () => {\n        this.client.sftp((err, sftp) => {\n          if (err) {\n            reject(this.fmtError(err));\n          } else {\n            this.sftp = sftp;\n            resolve(sftp);\n          }\n        });\n      };\n      this.on('ready', doReady);\n\n      try {\n        if (this.sftp) {\n          reject(\n            this.fmtError(\n              'An existing SFTP connection is already defined',\n              'connect',\n              errorCode.connect,\n            ),\n          );\n        } else {\n          this.client.connect(config);\n        }\n      } catch (err) {\n        this.end();\n        reject(err);\n      }\n    }).finally(() => {\n      this.removeListener('ready', doReady);\n      removeTempListeners(this, listeners, 'getConnection');\n      this._resetEventFlags();\n    });\n  }\n\n  /**\n   * @async\n   *\n   * Returns the real absolute path on the remote server. Is able to handle\n   * both '.' and '..' in path names, but not '~'. If the path is relative\n   * then the current working directory is prepended to create an absolute path.\n   * Returns undefined if the path does not exists.\n   *\n   * @param {String} remotePath - remote path, may be relative\n   * @param {Boolean} addListeners - (Optional) add event listeners. Default = true\n   * @returns {Promise<String>} - remote absolute path or ''\n   */\n  realPath(remotePath, addListeners = true) {\n    let listeners;\n    return new Promise((resolve, reject) => {\n      if (addListeners) {\n        listeners = addTempListeners(this, 'realPath', reject);\n      }\n      this.sftp.realpath(remotePath, (err, absPath) => {\n        if (err) {\n          if (err.code === 2) {\n            resolve('');\n          } else {\n            reject(this.fmtError(`${err.message} ${remotePath}`, 'realPath', err.code));\n          }\n        }\n        resolve(absPath);\n      });\n    }).finally(() => {\n      if (addListeners) {\n        removeTempListeners(this, listeners, 'realPath');\n        this._resetEventFlags();\n      }\n    });\n  }\n\n  /**\n   * @async\n   *\n   * Return the current workding directory path\n   *\n   * @returns {Promise<String>} - current remote working directory\n   */\n  cwd() {\n    return this.realPath('.');\n  }\n\n  /**\n   * Retrieves attributes for path using cmd, which is either\n   * this.sftp.stat or this.sftp.lstat\n   *\n   * @param {Function} cmd - either this.sftp.stat or this.sftp.lstat\n   * @param {String} remotePath - a string containing the path to a file\n   * @param {Boolean} addListeners - (Optional) if true add event listeners. Default true.\n   * @return {Promise<Object>} stats - attributes info\n   */\n  _xstat(cmd, aPath, addListeners = true) {\n    let listeners;\n    return new Promise((resolve, reject) => {\n      const cb = (err, stats) => {\n        if (err) {\n          if (err.code === 2 || err.code === 4) {\n            reject(this.fmtError(`No such file: ${aPath}`, '_xstat', errorCode.notexist));\n          } else {\n            reject(this.fmtError(`${err.message} ${aPath}`, '_xstat', err.code));\n          }\n        } else {\n          const result = {\n            mode: stats.mode,\n            uid: stats.uid,\n            gid: stats.gid,\n            size: stats.size,\n            accessTime: stats.atime * 1000,\n            modifyTime: stats.mtime * 1000,\n            isDirectory: stats.isDirectory(),\n            isFile: stats.isFile(),\n            isBlockDevice: stats.isBlockDevice(),\n            isCharacterDevice: stats.isCharacterDevice(),\n            isSymbolicLink: stats.isSymbolicLink(),\n            isFIFO: stats.isFIFO(),\n            isSocket: stats.isSocket(),\n          };\n          resolve(result);\n        }\n      };\n      if (addListeners) {\n        listeners = addTempListeners(this, '_xstat', reject);\n      }\n      if (cmd === 'stat') {\n        this.sftp.stat(aPath, cb);\n      } else {\n        this.sftp.lstat(aPath, cb);\n      }\n    }).finally(() => {\n      if (addListeners) {\n        removeTempListeners(this, listeners, '_xstat');\n        this._resetEventFlags();\n      }\n    });\n  }\n\n  /*\n   * Use the stat command to obtain attributes associated with a remote path.\n   * THe difference between stat and lstat is that stat, in the case of symbolic\n   * links, will return the attributes associated with the target of the link. With\n   * lstat, attributes associated with the symbolic link rather than the target are\n   * returned.\n   *\n   * @param {String} remotePath - path to an object on the remote server\n   * @return {Promise<Object>} stats - attributes info\n   */\n  async stat(remotePath) {\n    try {\n      haveConnection(this, 'stat');\n      return await this._xstat('stat', remotePath);\n    } catch (err) {\n      throw err.custom ? err : this.fmtError(err, 'stat', err.code);\n    }\n  }\n\n  /*\n   * Use the lstat command to obtain attributes associated with a remote path.\n   * THe difference between stat and lstat is that stat, in the case of symbolic\n   * links, will return the attributes associated with the target of the link. With\n   * lstat, attributes associated with the symbolic link rather than the target are\n   * returned.\n   *\n   * @param {String} remotePath - path to an object on the remote server\n   * @return {Promise<Object>} stats - attributes info\n   */\n  async lstat(remotePath) {\n    try {\n      haveConnection(this, 'lstat');\n      return await this._xstat('lstat', remotePath);\n    } catch (err) {\n      throw err.custom ? err : this.fmtError(err, 'lstat', err.code);\n    }\n  }\n\n  /**\n   * @async\n   *\n   * Tests to see if an object exists. If it does, return the type of that object\n   * (in the format returned by list). If it does not exist, return false.\n   *\n   * @param {string} remotePath - path to the object on the sftp server.\n   *\n   * @return {Promise<Boolean|String>} returns false if object does not exist. Returns type of\n   *                   object if it does\n   */\n  async exists(remotePath) {\n    try {\n      if (remotePath === '.') {\n        return 'd';\n      }\n      const info = await this.lstat(remotePath);\n      if (info.isDirectory) {\n        return 'd';\n      } else if (info.isSymbolicLink) {\n        return 'l';\n      } else if (info.isFile) {\n        return '-';\n      } else {\n        return false;\n      }\n    } catch (err) {\n      if (err.code === errorCode.notexist) {\n        return false;\n      }\n      throw err.custom ? err : this.fmtError(err.message, 'exists', err.code);\n    }\n  }\n\n  /**\n   * @async\n   *\n   * List contents of a remote directory. If a pattern is provided,\n   * filter the results to only include files with names that match\n   * the supplied pattern. Return value is an array of file entry\n   * objects that include properties for type, name, size, modifyTime,\n   * accessTime, rights {user, group other}, owner and group.\n   *\n   * @param {String} remotePath - path to remote directory\n   * @param {function} filter - a filter function used to select return entries\n   * @param {Boolean} addListeners - (Optional) if true, add listeners. Default true\n   * @returns {Promise<Array>} array of file description objects\n   */\n  list(remotePath, filter, addListeners = true) {\n    let listeners;\n    return new Promise((resolve, reject) => {\n      if (addListeners) {\n        listeners = addTempListeners(this, 'list', reject);\n      }\n      if (haveConnection(this, 'list', reject)) {\n        this.sftp.readdir(remotePath, (err, fileList) => {\n          if (err) {\n            reject(this.fmtError(`${err.message} ${remotePath}`, 'list', err.code));\n          } else {\n            const reg = /-/gi;\n            const newList = fileList.map((item) => {\n              return {\n                type: item.longname.slice(0, 1),\n                name: item.filename,\n                size: item.attrs.size,\n                modifyTime: item.attrs.mtime * 1000,\n                accessTime: item.attrs.atime * 1000,\n                rights: {\n                  user: item.longname.slice(1, 4).replaceAll(reg, ''),\n                  group: item.longname.slice(4, 7).replaceAll(reg, ''),\n                  other: item.longname.slice(7, 10).replaceAll(reg, ''),\n                },\n                owner: item.attrs.uid,\n                group: item.attrs.gid,\n                longname: item.longname,\n              };\n            });\n            if (filter) {\n              resolve(newList.filter((item) => filter(item)));\n            } else {\n              resolve(newList);\n            }\n          }\n        });\n      }\n    }).finally(() => {\n      if (addListeners) {\n        removeTempListeners(this, listeners, 'list');\n        this._resetEventFlags();\n      }\n    });\n  }\n\n  /**\n   * get file\n   *\n   * If a dst argument is provided, it must be either a string, representing the\n   * local path to where the data will be put, a stream, in which case data is\n   * piped into the stream or undefined, in which case the data is returned as\n   * a Buffer object.\n   *\n   * @param {String} remotePath - remote file path\n   * @param {string|stream|undefined} dst - data destination\n   * @param {Object} options - options object with supported properties of readStreamOptions,\n   *                          writeStreamOptions and pipeOptions.\n   * @param {Boolean} addListeners - (Optional) if true, add listeners. Default true\n   *\n   * *Important Note*: The ability to set ''autoClose' on read/write streams and 'end' on pipe() calls\n   * is no longer supported. New methods 'createReadStream()' and 'createWriteStream()' have been\n   * added to support low-level access to stream objects.\n   *\n   * @return {Promise<String|Stream|Buffer>}\n   */\n  get(remotePath, dst, options, addListeners = true) {\n    let listeners, rdr, wtr;\n    return new Promise((resolve, reject) => {\n      if (addListeners) {\n        listeners = addTempListeners(this, 'get', reject);\n      }\n      if (haveConnection(this, 'get', reject)) {\n        options = {\n          readStreamOptions: { ...options?.readStreamOptions, autoClose: true },\n          writeStreamOptions: {\n            ...options?.writeStreamOptions,\n            autoClose: true,\n          },\n          pipeOptions: { ...options?.pipeOptions, end: true },\n        };\n        rdr = this.sftp.createReadStream(remotePath, options.readStreamOptions);\n        rdr.on('error', (err) => {\n          if (dst && typeof dst === 'string' && wtr && !wtr.destroyed) {\n            wtr.destroy();\n          }\n          reject(this.fmtError(`${err.message} ${remotePath}`, 'get', err.code));\n        });\n        if (dst === undefined) {\n          // no dst specified, return buffer of data\n          wtr = concat((buff) => {\n            resolve(buff);\n          });\n        } else if (typeof dst === 'string') {\n          // dst local file path\n          const localCheck = haveLocalCreate(dst);\n          if (localCheck.status) {\n            wtr = fs.createWriteStream(dst, options.writeStreamOptions);\n          } else {\n            reject(\n              this.fmtError(\n                `Bad path: ${dst}: ${localCheck.details}`,\n                'get',\n                localCheck.code,\n              ),\n            );\n          }\n        } else {\n          wtr = dst;\n        }\n        wtr.on('error', (err) => {\n          reject(\n            this.fmtError(\n              `${err.message} ${typeof dst === 'string' ? dst : '<stream>'}`,\n              'get',\n              err.code,\n            ),\n          );\n        });\n        rdr.once('end', () => {\n          if (typeof dst === 'string') {\n            resolve(dst);\n          } else if (dst !== undefined) {\n            resolve(wtr);\n          }\n        });\n        rdr.pipe(wtr, options.pipeOptions);\n      }\n    }).finally(() => {\n      if (rdr && !rdr.destroyed) {\n        rdr.destroy();\n      }\n      if (addListeners) {\n        removeTempListeners(this, listeners, 'get');\n        this._resetEventFlags();\n      }\n    });\n  }\n\n  /**\n   * Use SSH2 fastGet for downloading the file.\n   * Downloads a file at remotePath to localPath using parallel reads\n   * for faster throughput.\n   *\n   * WARNING: The functionality of fastGet is heavily dependent on the capabilities\n   * of the remote SFTP server. Not all sftp server support or fully support this\n   * functionality. See the Platform Quirks & Warnings section of the README.\n   *\n   * @param {String} remotePath\n   * @param {String} localPath\n   * @param {Object} options\n   * @return {Promise<String>} the result of downloading the file\n   */\n  _fastGet(rPath, lPath, opts, addListeners = true) {\n    let listeners;\n    return new Promise((resolve, reject) => {\n      if (addListeners) {\n        listeners = addTempListeners(this, '_fastGet', reject);\n      }\n      if (haveConnection(this, '_fastGet', reject)) {\n        this.sftp.fastGet(rPath, lPath, opts, (err) => {\n          if (err) {\n            reject(this.fmtError(`${err.message} Remote: ${rPath} Local: ${lPath}`));\n          }\n          resolve(`${rPath} was successfully download to ${lPath}!`);\n        });\n      }\n    }).finally(() => {\n      if (addListeners) {\n        removeTempListeners(this, listeners, '_fastGet');\n        this._resetEventFlags();\n      }\n    });\n  }\n\n  async fastGet(remotePath, localPath, options) {\n    try {\n      const ftype = await this.exists(remotePath);\n      if (ftype !== '-') {\n        const msg = `${ftype ? 'Not a regular file' : 'No such file '} ${remotePath}`;\n        throw this.fmtError(msg, 'fastGet', errorCode.badPath);\n      }\n      const localCheck = haveLocalCreate(localPath);\n      if (!localCheck.status) {\n        throw this.fmtError(\n          `Bad path: ${localPath}: ${localCheck.details}`,\n          'fastGet',\n          errorCode.badPath,\n        );\n      }\n      return await this._fastGet(remotePath, localPath, options);\n    } catch (err) {\n      throw this.fmtError(err, 'fastGet');\n    }\n  }\n\n  /**\n   * Use SSH2 fastPut for uploading the file.\n   * Uploads a file from localPath to remotePath using parallel reads\n   * for faster throughput.\n   *\n   * See 'fastPut' at\n   * https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md\n   *\n   * WARNING: The fastPut functionality is heavily dependent on the capabilities of\n   * the remote sftp server. Many sftp servers do not support or do not fully support this\n   * functionality. See the Platform Quirks & Warnings section of the README for more details.\n   *\n   * @param {String} localPath - path to local file to put\n   * @param {String} remotePath - destination path for put file\n   * @param {Object} options - additonal fastPut options\n   * @param {Boolean} addListeners - (Optional) if true, add listeners. Default true.\n   * @return {Promise<String>} the result of downloading the file\n   */\n  _fastPut(lPath, rPath, opts, addListeners = true) {\n    let listeners;\n    return new Promise((resolve, reject) => {\n      if (addListeners) {\n        listeners = addTempListeners(this, '_fastPut', reject);\n      }\n      if (haveConnection(this, '_fastPut', reject)) {\n        this.sftp.fastPut(lPath, rPath, opts, (err) => {\n          if (err) {\n            reject(\n              this.fmtError(\n                `${err.message} Local: ${lPath} Remote: ${rPath}`,\n                'fastPut',\n                err.code,\n              ),\n            );\n          }\n          resolve(`${lPath} was successfully uploaded to ${rPath}!`);\n        });\n      }\n    }).finally(() => {\n      if (addListeners) {\n        removeTempListeners(this, listeners, '_fastPut');\n        this._resetEventFlags();\n      }\n    });\n  }\n\n  async fastPut(localPath, remotePath, options) {\n    try {\n      const localCheck = haveLocalAccess(localPath);\n      if (!localCheck.status) {\n        throw this.fmtError(\n          `Bad path: ${localPath}: ${localCheck.details}`,\n          'fastPut',\n          localCheck.code,\n        );\n      } else if (localCheck.status && localExists(localPath) === 'd') {\n        throw this.fmtError(\n          `Bad path: ${localPath} not a regular file`,\n          'fastgPut',\n          errorCode.badPath,\n        );\n      }\n      return await this._fastPut(localPath, remotePath, options);\n    } catch (e) {\n      throw e.custom ? e : this.fmtError(e.message, 'fastPut', e.code);\n    }\n  }\n\n  /**\n   * Create a file on the remote server. The 'src' argument\n   * can be a buffer, string or read stream. If 'src' is a string, it\n   * should be the path to a local file.\n   *\n   * @param  {String|Buffer|stream} localSrc - source data to use\n   * @param  {String} remotePath - path to remote file\n   * @param  {Object} options - options used for read, write stream and pipe configuration\n   *                            value supported by node. Allowed properties are readStreamOptions,\n   *                            writeStreamOptions and pipeOptions.\n   *\n   * *Important Note*: The ability to set ''autoClose' on read/write streams and 'end' on pipe() calls\n   * is no longer supported. New methods 'createReadStream()' and 'createWriteStream()' have been\n   * added to support low-level access to stream objects.\n   *\n   * @return {Promise<String>}\n   */\n  _put(lPath, rPath, opts, addListeners = true) {\n    let listeners, wtr, rdr;\n    return new Promise((resolve, reject) => {\n      if (addListeners) {\n        listeners = addTempListeners(this, '_put', reject);\n      }\n      opts = {\n        readStreamOptions: { ...opts?.readStreamOptions, autoClose: true },\n        writeStreamOptions: { ...opts?.writeStreamOptions, autoClose: true },\n        pipeOptions: { ...opts?.pipeOptions, end: true },\n      };\n      if (haveConnection(this, '_put', reject)) {\n        wtr = this.sftp.createWriteStream(rPath, opts.writeStreamOptions);\n        wtr.on('error', (err) => {\n          if (typeof lPath === 'string' && rdr && !rdr.destroyed) {\n            rdr.destroy();\n          }\n          reject(\n            this.fmtError(\n              `Write stream error: ${err.message} ${rPath}`,\n              '_put',\n              err.code,\n            ),\n          );\n        });\n        wtr.once('close', () => {\n          resolve(`Uploaded data stream to ${rPath}`);\n        });\n        if (lPath instanceof Buffer) {\n          wtr.end(lPath);\n        } else {\n          if (typeof lPath === 'string') {\n            rdr = fs.createReadStream(lPath, opts.readStreamOptions);\n          } else {\n            rdr = lPath;\n          }\n          rdr.on('error', (err) => {\n            reject(\n              this.fmtError(\n                `Read stream error: ${err.message} ${\n                  typeof lPath === 'string' ? lPath : '<stream>'\n                }`,\n                '_put',\n                err.code,\n              ),\n            );\n          });\n          rdr.pipe(wtr, opts.pipeOptions);\n        }\n      }\n    }).finally(() => {\n      if (wtr && !wtr.destroyed) {\n        wtr.destroy();\n      }\n      if (addListeners) {\n        removeTempListeners(this, listeners, '_put');\n        this._resetEventFlags();\n      }\n    });\n  }\n\n  async put(localSrc, remotePath, options) {\n    try {\n      if (typeof localSrc === 'string') {\n        const localCheck = haveLocalAccess(localSrc);\n        if (!localCheck.status) {\n          throw this.fmtError(\n            `Bad path: ${localSrc} ${localCheck.details}`,\n            'put',\n            localCheck.code,\n          );\n        }\n      }\n      return await this._put(localSrc, remotePath, options);\n    } catch (e) {\n      throw e.custom ? e : this.fmtError(`Re-thrown: ${e.message}`, 'put', e.code);\n    }\n  }\n\n  /**\n   * Append to an existing remote file\n   *\n   * @param  {Buffer|stream} input\n   * @param  {String} remotePath\n   * @param  {Object} options\n   * @return {Promise<String>}\n   */\n  _append(input, rPath, opts, addListeners = true) {\n    let listeners;\n    return new Promise((resolve, reject) => {\n      if (addListeners) {\n        listeners = addTempListeners(this, '_append', reject);\n      }\n      if (haveConnection(this, '_append', reject)) {\n        opts.flags = 'a';\n        const stream = this.sftp.createWriteStream(rPath, opts);\n        stream.on('error', (err) => {\n          reject(this.fmtError(`${err.message} ${rPath}`, 'append', err.code));\n        });\n        stream.on('close', () => {\n          resolve(`Appended data to ${rPath}`);\n        });\n        if (input instanceof Buffer) {\n          stream.write(input);\n          stream.end();\n        } else {\n          input.pipe(stream);\n        }\n      }\n    }).finally(() => {\n      if (addListeners) {\n        removeTempListeners(this, listeners, '_append');\n        this._resetEventFlags();\n      }\n    });\n  }\n\n  async append(input, remotePath, options = {}) {\n    try {\n      if (typeof input === 'string') {\n        throw this.fmtError(\n          'Cannot append one file to another',\n          'append',\n          errorCode.badPath,\n        );\n      }\n      const fileType = await this.exists(remotePath);\n      if (fileType && fileType === 'd') {\n        throw this.fmtError(\n          `Bad path: ${remotePath}: cannot append to a directory`,\n          'append',\n          errorCode.badPath,\n        );\n      }\n      return await this._append(input, remotePath, options);\n    } catch (e) {\n      throw e.custom ? e : this.fmtError(e.message, 'append', e.code);\n    }\n  }\n\n  /**\n   * @async\n   *\n   * Make a directory on remote server\n   *\n   * @param {string} remotePath - remote directory path.\n   * @param {boolean} recursive - if true, recursively create directories\n   * @return {Promise<String>}\n   */\n  _doMkdir(p, addListeners = true) {\n    let listeners;\n    return new Promise((resolve, reject) => {\n      if (addListeners) {\n        listeners = addTempListeners(this, '_doMkdir', reject);\n      }\n      this.sftp.mkdir(p, (err) => {\n        if (err) {\n          if (err.code === 4) {\n            //fix for windows dodgy error messages\n            reject(\n              this.fmtError(\n                `Bad path: ${p} permission denied`,\n                '_doMkdir',\n                errorCode.badPath,\n              ),\n            );\n          } else if (err.code === 2) {\n            reject(\n              this.fmtError(\n                `Bad path: ${p} parent not a directory or not exist`,\n                '_doMkdir',\n                errorCode.badPath,\n              ),\n            );\n          } else {\n            reject(this.fmtError(`${err.message} ${p}`, '_doMkdir', err.code));\n          }\n        } else {\n          resolve(`${p} directory created`);\n        }\n      });\n    }).finally(() => {\n      if (addListeners) {\n        removeTempListeners(this, listeners, '_doMkdir');\n        this._resetEventFlags();\n      }\n    });\n  }\n\n  async _mkdir(remotePath, recursive) {\n    try {\n      const rPath = await normalizeRemotePath(this, remotePath);\n      const targetExists = await this.exists(rPath);\n      if (targetExists && targetExists !== 'd') {\n        throw this.fmtError(\n          `Bad path: ${rPath} already exists as a file`,\n          '_mkdir',\n          errorCode.badPath,\n        );\n      } else if (targetExists) {\n        return `${rPath} already exists`;\n      }\n      if (!recursive) {\n        return await this._doMkdir(rPath);\n      }\n      const dir = parse(rPath).dir;\n      if (dir) {\n        const dirExists = await this.exists(dir);\n        if (!dirExists) {\n          await this._mkdir(dir, true);\n        } else if (dirExists !== 'd') {\n          throw this.fmtError(\n            `Bad path: ${dir} not a directory`,\n            '_mkdir',\n            errorCode.badPath,\n          );\n        }\n      }\n      return await this._doMkdir(rPath);\n    } catch (err) {\n      throw err.custom\n        ? err\n        : this.fmtError(`${err.message} ${remotePath}`, '_mkdir', err.code);\n    }\n  }\n\n  async mkdir(remotePath, recursive = false) {\n    try {\n      haveConnection(this, 'mkdir');\n      return await this._mkdir(remotePath, recursive);\n    } catch (err) {\n      throw this.fmtError(`${err.message}`, 'mkdir', err.code);\n    }\n  }\n\n  /**\n   * @async\n   *\n   * Remove directory on remote server\n   *\n   * @param {string} remotePath - path to directory to be removed\n   * @param {boolean} recursive - if true, remove directories/files in target\n   *                             directory\n   * @return {Promise<String>}\n   */\n  async rmdir(remoteDir, recursive = false) {\n    const _rmdir = (dir) => {\n      let listeners;\n      return new Promise((resolve, reject) => {\n        listeners = addTempListeners(this, '_rmdir', reject);\n        this.sftp.rmdir(dir, (err) => {\n          if (err) {\n            reject(this.fmtError(`${err.message} ${dir}`, 'rmdir', err.code));\n          }\n          resolve('Successfully removed directory');\n        });\n      }).finally(() => {\n        removeTempListeners(this, listeners, '_rmdir');\n        this._resetEventFlags();\n      });\n    };\n\n    const _delFiles = (path, fileList) => {\n      let listeners;\n      return new Promise((resolve, reject) => {\n        listeners = addTempListeners(this, '_delFiles', reject);\n        const pList = [];\n        for (const f of fileList) {\n          pList.push(this.delete(`${path}/${f.name}`, true, false));\n        }\n        resolve(pList);\n      })\n        .then((p) => {\n          return Promise.all(p);\n        })\n        .finally(() => {\n          removeTempListeners(this, listeners, '_delFiles');\n        });\n    };\n\n    try {\n      const absPath = await normalizeRemotePath(this, remoteDir);\n      const existStatus = await this.exists(absPath);\n      if (!existStatus) {\n        throw this.fmtError(\n          `Bad Path: ${remoteDir}: No such directory`,\n          'rmdir',\n          errorCode.badPath,\n        );\n      }\n      if (existStatus !== 'd') {\n        throw this.fmtError(\n          `Bad Path: ${remoteDir}: Not a directory`,\n          'rmdir',\n          errorCode.badPath,\n        );\n      }\n      if (!recursive) {\n        return await _rmdir(absPath);\n      }\n      const listing = await this.list(absPath);\n      if (!listing.length) {\n        return await _rmdir(absPath);\n      }\n      const fileList = listing.filter((i) => i.type !== 'd');\n      const dirList = listing.filter((i) => i.type === 'd');\n      await _delFiles(absPath, fileList);\n      for (const d of dirList) {\n        await this.rmdir(`${absPath}/${d.name}`, true);\n      }\n      await _rmdir(absPath);\n      return 'Successfully removed directory';\n    } catch (err) {\n      throw err.custom\n        ? err\n        : this.fmtError(`${err.message} ${remoteDir}`, 'rmdir', err.code);\n    }\n  }\n\n  /**\n   * @async\n   *\n   * Delete a file on the remote SFTP server\n   *\n   * @param {string} remotePath - path to the file to delete\n   * @param {boolean} notFoundOK - if true, ignore errors for missing target.\n   *                               Default is false.\n   * @return {Promise<String>} with string 'Successfully deleted file' once resolved\n   */\n  delete(remotePath, notFoundOK = false, addListeners = true) {\n    let listeners;\n    return new Promise((resolve, reject) => {\n      if (addListeners) {\n        listeners = addTempListeners(this, 'delete', reject);\n      }\n      this.sftp.unlink(remotePath, (err) => {\n        if (err) {\n          if (notFoundOK && err.code === 2) {\n            resolve(`Successfully deleted ${remotePath}`);\n          } else {\n            reject(this.fmtError(`${err.message} ${remotePath}`, 'delete', err.code));\n          }\n        }\n        resolve(`Successfully deleted ${remotePath}`);\n      });\n    }).finally(() => {\n      if (addListeners) {\n        removeTempListeners(this, listeners, 'delete');\n        this._resetEventFlags();\n      }\n    });\n  }\n\n  /**\n   * @async\n   *\n   * Rename a file on the remote SFTP repository\n   *\n   * @param {string} fromPath - path to the file to be renamed.\n   * @param {string} toPath - path to the new name.\n   * @param {Boolean} addListeners - (Optional) if true, add listeners. Default true\n   *\n   * @return {Promise<String>}\n   */\n  rename(fPath, tPath, addListeners = true) {\n    let listeners;\n    return new Promise((resolve, reject) => {\n      if (addListeners) {\n        listeners = addTempListeners(this, 'rename', reject);\n      }\n      if (haveConnection(this, 'rename', reject)) {\n        this.sftp.rename(fPath, tPath, (err) => {\n          if (err) {\n            reject(\n              this.fmtError(\n                `${err.message} From: ${fPath} To: ${tPath}`,\n                '_rename',\n                err.code,\n              ),\n            );\n          }\n          resolve(`Successfully renamed ${fPath} to ${tPath}`);\n        });\n      }\n    }).finally(() => {\n      if (addListeners) {\n        removeTempListeners(this, listeners, 'rename');\n        this._resetEventFlags();\n      }\n    });\n  }\n\n  /**\n   * @async\n   *\n   * Rename a file on the remote SFTP repository using the SSH extension\n   * posix-rename@openssh.com using POSIX atomic rename. (Introduced in SSH 4.8)\n   *\n   * @param {string} fromPath - path to the file to be renamed.\n   * @param {string} toPath - path  the new name.\n   * @param {Boolean} addListeners - (Optional) if true, add listeners. Default true\n   *\n   * @return {Promise<String>}\n   */\n  posixRename(fPath, tPath, addListeners = true) {\n    let listeners;\n    return new Promise((resolve, reject) => {\n      if (addListeners) {\n        listeners = addTempListeners(this, 'posixRename', reject);\n      }\n      if (haveConnection(this, 'posixRename', reject)) {\n        this.sftp.ext_openssh_rename(fPath, tPath, (err) => {\n          if (err) {\n            reject(\n              this.fmtError(\n                `${err.message} From: ${fPath} To: ${tPath}`,\n                '_posixRename',\n                err.code,\n              ),\n            );\n          }\n          resolve(`Successful POSIX rename ${fPath} to ${tPath}`);\n        });\n      }\n    }).finally(() => {\n      removeTempListeners(this, listeners, 'posixRename');\n      this._resetEventFlags();\n    });\n  }\n\n  /**\n   * @async\n   *\n   * Change the mode of a remote file on the SFTP repository\n   *\n   * @param {string} remotePath - path to the remote target object.\n   * @param {number | string} mode - the new octal mode to set\n   * @param {boolean} addListeners - (Optional) if true, add listeners. Default true.\n   *\n   * @return {Promise<String>}\n   */\n  chmod(rPath, mode, addListeners = true) {\n    let listeners;\n    return new Promise((resolve, reject) => {\n      if (addListeners) {\n        listeners = addTempListeners(this, 'chmod', reject);\n      }\n      if (haveConnection(this, 'chmod', reject)) {\n        this.sftp.chmod(rPath, mode, (err) => {\n          if (err) {\n            reject(this.fmtError(`${err.message} ${rPath}`, '_chmod', err.code));\n          }\n          resolve('Successfully change file mode');\n        });\n      }\n    }).finally(() => {\n      if (addListeners) {\n        removeTempListeners(this, listeners, 'chmod');\n        this._resetEventFlags();\n      }\n    });\n  }\n\n  /**\n   * @async\n   *\n   * Upload the specified source directory to the specified destination\n   * directory. All regular files and sub-directories are uploaded to the remote\n   * server.\n   * @param {String} srcDir - local source directory\n   * @param {String} dstDir - remote destination directory\n   * @param {Object} options - (Optional) An object with 2 supported properties,\n   * 'filter' and 'useFastput'. Filter is a function of two arguments.\n   * The first argument is the full path of a directory entry from the directory\n   * to be uploaded and the second argument is a boolean, which will be true if\n   * the target path is for a directory. If the function returns true, this item\n   * will be uploaded and excluded when it returns false. The 'useFastput' property is a\n   * boolean value. When true, the 'fastPut()' method will be used to upload files. Default\n   * is to use the slower, but more supported 'put()' method.\n   *\n   * @returns {Promise<Array>}\n   */\n  async uploadDir(srcDir, dstDir, options) {\n    const getRemoteStatus = async (dstDir) => {\n      const absDstDir = await normalizeRemotePath(this, dstDir);\n      const status = await this.exists(absDstDir);\n      if (status && status !== 'd') {\n        throw this.fmtError(\n          `Bad path ${absDstDir} Not a directory`,\n          'getRemoteStatus',\n          errorCode.badPath,\n        );\n      }\n      return { remoteDir: absDstDir, remoteStatus: status };\n    };\n\n    const checkLocalStatus = (srcDir) => {\n      const srcType = localExists(srcDir);\n      if (!srcType) {\n        throw this.fmtError(\n          `Bad path: ${srcDir} not exist`,\n          'getLocalStatus',\n          errorCode.badPath,\n        );\n      }\n      if (srcType !== 'd') {\n        throw this.fmtError(\n          `Bad path: ${srcDir}: not a directory`,\n          'getLocalStatus',\n          errorCode.badPath,\n        );\n      }\n      return srcType;\n    };\n\n    const uploadFiles = async (srcDir, dstDir, fileList, useFastput) => {\n      let listeners = addTempListeners(this, 'uploadFiles');\n\n      try {\n        const uploadList = [];\n        for (const f of fileList) {\n          const src = join(srcDir, f.name);\n          const dst = `${dstDir}/${f.name}`;\n          uploadList.push([src, dst]);\n        }\n        const uploadGroups = partition(uploadList, this.promiseLimit);\n        const func = useFastput ? this._fastPut.bind(this) : this._put.bind(this);\n        const uploadResults = [];\n        for (const group of uploadGroups) {\n          const pList = [];\n          for (const [src, dst] of group) {\n            pList.push(func(src, dst, null, false));\n            this.client.emit('upload', { source: src, destination: dst });\n          }\n          const groupResults = await Promise.all(pList);\n          for (const r of groupResults) {\n            uploadResults.push(r);\n          }\n        }\n        return uploadResults;\n      } catch (e) {\n        throw this.fmtError(`${e.message} ${srcDir} to ${dstDir}`, 'uploadFiles', e.code);\n      } finally {\n        removeTempListeners(this, listeners, uploadFiles);\n        this._resetEventFlags();\n      }\n    };\n\n    try {\n      haveConnection(this, 'uploadDir');\n      const { remoteDir, remoteStatus } = await getRemoteStatus(dstDir);\n      checkLocalStatus(srcDir);\n      if (!remoteStatus) {\n        await this._mkdir(remoteDir, true);\n      }\n      let dirEntries = fs.readdirSync(srcDir, {\n        encoding: 'utf8',\n        withFileTypes: true,\n      });\n      if (options?.filter) {\n        dirEntries = dirEntries.filter((item) =>\n          options.filter(join(srcDir, item.name), item.isDirectory()),\n        );\n      }\n      const dirUploads = dirEntries.filter((item) => item.isDirectory());\n      const fileUploads = dirEntries.filter((item) => !item.isDirectory());\n      await uploadFiles(srcDir, remoteDir, fileUploads, options?.useFastput);\n      for (const d of dirUploads) {\n        const src = join(srcDir, d.name);\n        const dst = `${remoteDir}/${d.name}`;\n        await this.uploadDir(src, dst, options);\n      }\n      return `${srcDir} uploaded to ${dstDir}`;\n    } catch (err) {\n      throw err.custom\n        ? err\n        : this.fmtError(`${err.message} ${srcDir}`, 'uploadDir', err.code);\n    }\n  }\n\n  /**\n   * @async\n   *\n   * Download the specified source directory to the specified destination\n   * directory. All regular files and sub-directories are downloaded to the local\n   * file system.\n   * @param {String} srcDir - remote source directory\n   * @param {String} dstDir - local destination directory\n   * @param {Object} options - (Optional) Object with 2 supported properties,\n   * 'filter' and 'useFastget'. The filter property is a function of two\n   * arguments. The first argument is the full path of the item to be downloaded\n   * and the second argument is a boolean, which will be true if the target path\n   * is for a directory. If the function returns true, the item will be\n   * downloaded and excluded if teh function returns false.\n   *\n   * @returns {Promise<Array>}\n   */\n  async downloadDir(srcDir, dstDir, options = { filter: null, useFastget: false }) {\n    const getDownloadList = async (srcDir, filter) => {\n      try {\n        const listing = await this.list(srcDir);\n        if (filter) {\n          return listing.filter((item) =>\n            filter(`${srcDir}/${item.name}`, item.type === 'd'),\n          );\n        }\n        return listing;\n      } catch (err) {\n        throw err.custom ? err : this.fmtError(err.message, '_getDownloadList', err.code);\n      }\n    };\n\n    const prepareDestination = (dst) => {\n      try {\n        const localCheck = haveLocalCreate(dst);\n        if (!localCheck.status && localCheck.details === 'permission denied') {\n          throw this.fmtError(\n            `Bad path: ${dst}: ${localCheck.details}`,\n            'prepareDestination',\n            localCheck.code,\n          );\n        } else if (localCheck.status && !localCheck.type) {\n          fs.mkdirSync(dst, { recursive: true });\n        } else if (localCheck.status && localCheck.type !== 'd') {\n          throw this.fmtError(\n            `Bad path: ${dstDir}: not a directory`,\n            '_prepareDestination',\n            errorCode.badPath,\n          );\n        }\n      } catch (err) {\n        throw err.custom\n          ? err\n          : this.fmtError(err.message, '_prepareDestination', err.code);\n      }\n    };\n\n    const downloadFiles = async (remotePath, localPath, fileList, useFastget) => {\n      let listeners = addTempListeners(this, 'downloadFIles');\n\n      try {\n        const downloadList = [];\n        for (const f of fileList) {\n          const src = `${remotePath}/${f.name}`;\n          const dst = join(localPath, f.name);\n          downloadList.push([src, dst]);\n        }\n        const downloadGroups = partition(downloadList, this.promiseLimit);\n        const func = useFastget ? this._fastGet.bind(this) : this.get.bind(this);\n        const downloadResults = [];\n        for (const group of downloadGroups) {\n          const pList = [];\n          for (const [src, dst] of group) {\n            pList.push(func(src, dst, null, false));\n            this.client.emit('download', { source: src, destination: dst });\n          }\n          const groupResults = await Promise.all(pList);\n          for (const r of groupResults) {\n            downloadResults.push(r);\n          }\n        }\n        return downloadResults;\n      } catch (e) {\n        throw this.fmtError(\n          `${e.message} ${srcDir} to ${dstDir}`,\n          'downloadFiles',\n          e.code,\n        );\n      } finally {\n        removeTempListeners(this, listeners, 'downloadFiles');\n        this._resetEventFlags();\n      }\n    };\n\n    try {\n      haveConnection(this, 'downloadDir');\n      const downloadList = await getDownloadList(srcDir, options.filter);\n      prepareDestination(dstDir);\n      const fileDownloads = downloadList.filter((i) => i.type !== 'd');\n      if (fileDownloads.length) {\n        await downloadFiles(srcDir, dstDir, fileDownloads, options.useFastget);\n      }\n      const dirDownloads = downloadList.filter((i) => i.type === 'd');\n      for (const d of dirDownloads) {\n        const src = `${srcDir}/${d.name}`;\n        const dst = join(dstDir, d.name);\n        await this.downloadDir(src, dst, options);\n      }\n      return `${srcDir} downloaded to ${dstDir}`;\n    } catch (err) {\n      throw err.custom\n        ? err\n        : this.fmtError(`${err.message}: ${srcDir}`, 'downloadDir', err.code);\n    }\n  }\n\n  /**\n   * Returns a read stream object. This is a low level method which will return a read stream\n   * connected to the remote file object specified as an argument. Client code is fully responsible\n   * for managing this stream object i.e. adding any necessary listeners and disposing of the object etc.\n   * See the SSH2 sftp documentation for details on possible options which can be used.\n   *\n   * @param {String} remotePath - path to remote file to attach stream to\n   * @param {Object} options - options to pass to the create stream process\n   *\n   * @returns {Object} a read stream object\n   */\n  createReadStream(remotePath, options) {\n    let listeners;\n    try {\n      listeners = addTempListeners(this, 'createReadStream');\n      haveConnection(this, 'createReadStream');\n      const stream = this.sftp.createReadStream(remotePath, options);\n      return stream;\n    } catch (err) {\n      throw err.custom ? err : this.fmtError(err.message, 'createReadStream', err.code);\n    } finally {\n      removeTempListeners(this, listeners, 'createReadStream');\n      this._resetEventFlags();\n    }\n  }\n\n  /**\n   * Create a write stream object connected to a file on the remote sftp server.\n   * This is a low level method which will return a write stream for the remote file specified\n   * in the 'remotePath' argument. Client code to responsible for managing this object once created.\n   * This includes disposing of file handles, setting up any necessary event listeners etc.\n   *\n   * @param {String} remotePath - path to the remote file on the sftp server\n   * @param (Object} options - options to pass to the create write stream process)\n   *\n   * @returns {Object} a stream object\n   */\n  createWriteStream(remotePath, options) {\n    let listeners;\n    try {\n      listeners = addTempListeners(this, 'createWriteStream');\n      haveConnection(this, 'createWriteStream');\n      const stream = this.sftp.createWriteStream(remotePath, options);\n      return stream;\n    } catch (err) {\n      throw err.custom ? err : this.fmtError(err.message, 'createWriteStream', err.code);\n    } finally {\n      removeTempListeners(this, listeners, 'createWriteStream');\n      this._resetEventFlags();\n    }\n  }\n\n  /**\n   * @async\n   *\n   * Make a remote copy of a remote file. Create a copy of a remote file on the remote\n   * server. It is assumed the directory where the copy will be placed already exists.\n   * The destination file must not already exist.\n   *\n   * @param {String} srcPath - path to the remote file to be copied\n   * @param {String} dstPath - destination path for the copy.\n   *\n   * @returns {String}.\n   */\n  _rcopy(srcPath, dstPath) {\n    return new Promise((resolve, reject) => {\n      const ws = this.sftp.createWriteStream(dstPath);\n      const rs = this.sftp.createReadStream(srcPath);\n      ws.on('error', (err) => {\n        reject(this.fmtError(`${err.message} ${dstPath}`, '_rcopy'));\n      });\n      rs.on('error', (err) => {\n        reject(this.fmtError(`${err.message} ${srcPath}`, '_rcopy'));\n      });\n      ws.on('close', () => {\n        resolve(`${srcPath} copied to ${dstPath}`);\n      });\n      rs.pipe(ws);\n    });\n  }\n\n  async rcopy(src, dst) {\n    let listeners;\n    try {\n      listeners = addTempListeners(this, 'rcopy');\n      haveConnection(this, 'rcopy');\n      const srcPath = await normalizeRemotePath(this, src);\n      const srcExists = await this.exists(srcPath);\n      if (!srcExists) {\n        throw this.fmtError(\n          `Source does not exist ${srcPath}`,\n          'rcopy',\n          errorCode.badPath,\n        );\n      }\n      if (srcExists !== '-') {\n        throw this.fmtError(`Source not a file ${srcPath}`, 'rcopy', errorCode.badPath);\n      }\n      const dstPath = await normalizeRemotePath(this, dst);\n      const dstExists = await this.exists(dstPath);\n      if (dstExists) {\n        throw this.fmtError(\n          `Destination already exists ${dstPath}`,\n          'rcopy',\n          errorCode.badPath,\n        );\n      }\n      return this._rcopy(srcPath, dstPath);\n    } catch (err) {\n      throw err.custom ? err : this.fmtError(err, 'rcopy');\n    } finally {\n      removeTempListeners(this, listeners, 'rcopy');\n      this._resetEventFlags();\n    }\n  }\n  /**\n   * @async\n   *\n   * End the SFTP connection\n   *\n   * @returns {Promise<Boolean>}\n   */\n  end() {\n    let endCloseHandler, listeners;\n    return new Promise((resolve, reject) => {\n      listeners = addTempListeners(this, 'end', reject);\n      this.endCalled = true;\n      endCloseHandler = () => {\n        this.sftp = undefined;\n        this.debugMsg('end: Connection closed');\n        resolve(true);\n      };\n      this.on('close', endCloseHandler);\n      if (this.sftp) {\n        this.debugMsg('end: Ending SFTP connection');\n        this.client.end();\n      } else {\n        // no actual connection exists - just resolve\n        this.debugMsg('end: Called when no connection active');\n        resolve(true);\n      }\n    }).finally(() => {\n      removeTempListeners(this, listeners, 'end');\n      this.removeListener('close', endCloseHandler);\n      this._resetEventFlags();\n    });\n  }\n}\n\nmodule.exports = SftpClient;\n"]}