Package Exports
- ssh2-sftp-client
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ssh2-sftp-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
SSH2 SFTP Client
a SFTP client for node.js, a wrapper for ssh2
Installation
npm install ssh2-sftp-client
Usage
let Client = require('ssh2-sftp-client');
let sftp = new Client();
sftp.connect({
host: '127.0.0.1',
port: '8080',
username: 'xx'
passphrase: 'xxx'
}).then(() => {
return sftp.list('/pathname');
}).then((data) => {
console.log(data, 'the data info');
}).catch((err) => {
console.log(err, 'catch error');
});
Documentation
the connection to server config pls see ssh2 client event.
list of methods: all the methods will return a Promise;
List
Retrieves a directory listing.
sftp.list(romoteFilePath)
directory info:
type: // file type(-, d, l)
name: // file name
size: // file size
modifyTime: // file timestamp of modified time
accessTime: // file timestamp of access time
rights: {
user:
group:
other:
},
owner: // user ID
group: // group ID
Get
get a new readable stream for path.
sftp.get(romoteFilePath, [useCompression]);
Put
upload a file. it can be localPath
or Buffer
or Stream
.
sftp.put(localFilePath, remoteFilePath, [useCompression]);
sftp.put(Buffer, remoteFilePath, [useCompression]);
sftp.put(Stream, remoteFilePath, [useCompression]);
Mkdir
create a new directory.
// recursive default is false, if true, it will create directory recursive
sftp.mkdir(remoteFilePath, recursive);
Rmdir
remove the directory or file.
// recursive default is false, if true, it will remove directory recursive even if is not empty
sftp.rmdir(localPath, recursive);
Delete
delete file.
sftp.delete(remoteFilePath);
Rename
rename/remove remoteSourcePath to remoteDestPath.
sftp.remove(remoteSourcePath, remoteDestPath);
FAQ
Log
- 2016.05.19:
- fix: multi image upload
- change: remove
this.client.sftp
toconnect
function