Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
ssh2-sftp
Advanced tools
Readme
SFTP client for node.js.
npm install ssh2-sftp
ex. dirs:
node-sftp
|- /build
|- index.html
|- page.html
|- /static
|- /js
|- index.js
|- page.js
|- /css
|- index.css
|- page.css
|- /down
const Sftp = require('ssh2-sftp');
var client = new Sftp({
"host": "192.168.1.1",
"port": 22,
"user": "root",
"password": "root",
"privateKey": fs.readFileSync('/.ssh/id_rsa') // password or privateKey
});
client.connect(callback);
Upload from local dirs: static
in ./build
to remote SFTP: /node-sftp/build
.
client.connect(() => {
let options = {
source: 'static', // ex. static static/js static/js/index.js
localPath: './build',
remotePath: '/node-sftp/build'
};
client.download(options, callback);
});
/* Remote SFTP dirs output:
* node-sftp
* |- /build
* |- /static
* |- /js
* |- index.js
* |- page.js
* |- /css
* |- index.css
* |- page.css
*/
Download from romate SFTP: static
in /node-sftp/build
to local: ./down
.
client.connect(() => {
let options = {
source: 'static', // ex. static static/js static/js/index.js
localPath: './down',
remotePath: '/node-sftp/build'
};
client.download(options, callback);
});
/* Local dirs output:
* node-sftp
* |- /build
* |- ...
* |- /down
* |- /static
* |- /js
* |- index.js
* |- page.js
* |- /css
* |- index.css
* |- page.css
*/
To create an instance of the wrapper use the following code:
var sftpClient = require('ssh2-sftp'),
client = new sftpClient(config);
config
containers the sftp server configuration:
'localhost'
'localhost'
After creating the new object you have to manually connect to the server bt using the connect
method:
client.connect(callback);
And passing the callback which should be executed when the client is ready.
upload(< Object > options,< Function > callback) - expand the options.source
paths using the glob module, upload all found files and directories to the specified options.remotePath
, and passing the callback which should be executed after the client uploaded successfully.
options
can have the following properties:
source
which should to be uploaded, if not set source
, upload all of files and directories. Supports files and directories. Default: ''
download(< Object > options,< Function > callback) - downloads the contents of options.remotePath
to options.localPath
if both exist, and passing the callback which should be executed after the client downloaded successfully.
options
can have the following properties:
source
which should to be downloaded. Supports files and directories, if not set source
, download all of files and directories. Default: ''
FAQs
SFTP client for node.js.
The npm package ssh2-sftp receives a total of 6 weekly downloads. As such, ssh2-sftp popularity was classified as not popular.
We found that ssh2-sftp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.