Skip to content

support chown #489

Description

@GaborTorma

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')
		}
	})
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions