Skip to content

Instantly share code, notes, and snippets.

@phainamikaze
Created August 23, 2021 08:01
Show Gist options
  • Select an option

  • Save phainamikaze/8b865c1ff030386a4cfdd3ca6be946ad to your computer and use it in GitHub Desktop.

Select an option

Save phainamikaze/8b865c1ff030386a4cfdd3ca6be946ad to your computer and use it in GitHub Desktop.
const fs = require('fs');
async function example() {
const client = new ftp.Client()
client.ftp.verbose = true
try {
const secureOptions = {
// Necessary only if the server requires client certificate authentication.
key: fs.readFileSync('client-key.pem'),
cert: fs.readFileSync('client-cert.pem'),
// Necessary only if the server uses a self-signed certificate.
ca: [ fs.readFileSync('server-cert.pem') ],
// Necessary only if the server's cert isn't for "localhost".
checkServerIdentity: () => { return null; },
};
await client.access({
host: "ftp.xxxx.xxxxx",
user: "[email protected]",
password: "xxxxxxx",
secure :true,
secureOptions : secureOptions
})
await client.ensureDir("/my/remote/directory")
console.log(await client.list())
await client.uploadFrom("temp/readme.txt", "readme.txt")
// await client.downloadTo("README_COPY.md", "README_FTP.md")
}
catch(err) {
console.log(err)
}
client.close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment