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.
easy-sftp-deploy
Advanced tools
Readme
Thusfar every sftp deploy package I've tried has been terrible, so I thought I'd make my own better one.
This package allows you to easily upload folders in your package directory to one or more servers.
You can add it to your project with either yarn or npm:
yarn add easy-sftp-deploy
npm install easy-sftp-deploy
Or you can run the cli directly:
npx easy-sftp-deploy --help
Both the cli and and javascript interface accept the same configuraton options.
The top level configuration accepts 4 options:
credentials: { [credentialID]: credentialConfig }
hosts: { [hostID]: hostConfig }
sourceFolders: { [sourceFolderID]: sourceFolderConfig }
deployments: [deploymentConfig]
The credential configuration options are all pretty self explanatory.
username: string
password: string (optional)
privateKey: string (optional)
For the host configuration you can specify the hostname and port as expected. There are also options for speeding up the connection using either fastPut for large files and/or parallelization for many files. Do keep in mind that both of these options might not work on all servers. But for the credentials, you need to reference one of the configured credentials. This allows you to more easily reuse credentials between multiple hosts without a giant configuration file.
hostname: string
port: number (optional, default is 22)
useFastPut: boolean (optional, default is false)
parallel: number (optional, default is 10)
credentialsID: string
For a source folder configuration you firstly specify a folder on your local system. This can be either a relative or absolute path. The program will then recursively locate all files in this folder automatically. By default it includes hidden dot files, and excludes empty directories. If you wish to change this you can do so with the includeDotFiles
and includeAllFolders
flags.
Then you can also specify a list of filters for this directory. Here micromatch will be used internally, so you can use all the same wildcard configurations as that library allows. The not empty match ("!") will always be added to this filterlist, and dotfiles will be matched, so keep this in mind when adding filters.
folder: string
filters: [string] (optional)
includeDotFiles: boolean (optional, default is true)
includeAllFolders: boolean (optional, default is false)
In the deployment config, you first have to specify a reference to both a host and a source folder.
Then you can specify a target folder on the remote host. Here the contents of the source folder will be uploaded to this target folder, so not the source folder itself. (If you wish to upload the source folder instead, you can change the source path and make use of the filters.)
It also has a couple flags you can set:
hostID: string
sourceFolderID: string
targetFolder: string
overwrite: boolean (optional, default is false)
clear: boolean (optional, default is false)
dryRun: boolean (optional, default is false)
This package only really exports two functions:
async DeployToSftp(config) -> boolean
Accept a configuration as javascript object, and process it. Returns true if successful.async DeployToSftpFromFile(configFilePath) -> boolean
Accept a configuration file path, and process it. Returns true if successful.You can import it with:
// ES6 Style
import { DeployToSftp } from 'easy-sftp-deploy';
// CommonJS Style
const { DeployToSftp } = require('easy-sftp-deploy');
This package can also be used from the command line. It can be started using npx
and accepts two options:
--config <config.json>
The path to the configuration file.--color <true | false>
Whether to use color in the output. (default is true)If no config is specified it will look for the config at ./sftp.deploy.json
.
Here a normal example, where a single directory is uploaded to two different servers using different credentials.
import { DeployToSftp } from 'easy-sftp-deploy';
await DeployToSftp({
credentials: {
boblogin: {
username: 'bob',
password: 'securepassword',
},
stevelogin: {
username: 'steve',
privateKey:
'-----BEGIN OPENSSH PRIVATE KEY-----\n...\n-----END OPENSSH PRIVATE KEY-----',
},
},
hosts: {
main: {
host: '1.2.3.4',
credentialsID: 'boblogin',
},
backup: {
host: '4.3.2.1',
credentialsID: 'stevelogin',
useFastPut: true,
parallel: 50,
},
},
sourceFolders: {
htmldist: {
folder: './dist',
filters: ['**/*.html'],
includeDotFiles: false,
includeAllFolders: true,
},
},
deployments: [
{
hostID: 'main',
srcID: 'htmldist',
dstFolder: '/var/www/',
clear: true,
overwrite: false,
dryRun: false,
},
{
hostID: 'backup',
srcID: 'htmldist',
dstFolder: '/var/www/',
clear: true,
},
],
});
You can also use the built in cli command to deploy to sftp. Here is an example that does the same as the code example above.
First you create a config file sftp.json
:
{
"credentials": { "main": { "username": "bob", "password": "pass" } },
"hosts": { "main": { "host": "1.2.1.2", "credentialsID": "main" } },
"sourceFolders": { "dist": { "folder": "./dist" } },
"deployments": [
{
"hostID": "main",
"srcID": "dist",
"dstFolder": "/destination",
"clear": true
}
]
}
Then you can run the cli command:
npx easy-sftp-deploy --config ./sftp.json
If you find any bugs, please open an issue, without feedback I'll never know they're there.
directory
property in sourceFolders
to folder
filter
property in sourceFolders
to filters
sourcefolders
property to sourceFolders
FAQs
Easily deploy files and directories to a server with sftp
The npm package easy-sftp-deploy receives a total of 0 weekly downloads. As such, easy-sftp-deploy popularity was classified as not popular.
We found that easy-sftp-deploy 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.