ssh2-sftp-client icon indicating copy to clipboard operation
ssh2-sftp-client copied to clipboard

support chown

Open GaborTorma opened this issue 2 years ago • 1 comments

Please support chown function.

I created it:

/**
 * @async
 *
 * Change the owner of a remote file on the SFTP repository
 *
 * @param {string} remotePath - path to the remote target object.
 * @param {number | string} uid - the owner id to set
 * @param {number | string} gid - the group id to set
 * @param {boolean} addListeners - (Optional) if true, add listeners. Default true.
 *
 * @return {Promise<String>}
 */
chown(rPath, uid, gid, addListeners = true) {
	let listeners
	return new Promise((resolve, reject) => {
		if (addListeners) {
			listeners = addTempListeners(this, 'chown', reject)
		}
		if (haveConnection(this, 'chown', reject)) {
			this.sftp.chown(rPath, uid, gid, (err) => {
				if (err) {
					reject(this.fmtError(`${err.message} ${rPath}`, '_chown', err.code))
				}
				resolve('Successfully change file owner')
			})
		}
	}).finally(() => {
		if (addListeners) {
			removeTempListeners(this, listeners, 'chown')
		}
	})
}

GaborTorma avatar Jun 23 '23 07:06 GaborTorma

Will try to add this for the next release.

At this point, there is no timeline as to when this will be.

theophilusx avatar Jun 24 '23 00:06 theophilusx