Docs · Clients

Node.js SFTP upload with ssh2-sftp-client

ssh2-sftp-client wraps the ssh2 library with promises. Without a hostVerifier it accepts any server key; this example accepts only the published fingerprints.

These steps use the SFTP Harbor endpoint data.sftpharbor.com and the example login yourserver.alice: your server's name, a dot, and the user name. Signed-in customers see the same steps with their own login on the dashboard's overview.

npm install ssh2-sftp-client. hostVerifier accepts only the published fingerprints.

upload.mjs
import { createHash } from "node:crypto";
import { readFileSync } from "node:fs";
import SftpClient from "ssh2-sftp-client";

const TRUSTED = new Set(["SHA256:…"]);

const sftp = new SftpClient();
await sftp.connect({
	host: "data.sftpharbor.com",
	port: 22,
	username: "yourserver.alice",
	privateKey: readFileSync("id_ed25519"),
	hostVerifier: (key) =>
		TRUSTED.has("SHA256:" + createHash("sha256").update(key).digest("base64").replace(/=+$/, "")),
});
await sftp.put("report.csv", "/report.csv");
await sftp.end();

Host keys are also listed on the security page, with SSHFP records. When keys are rotated, the new ones are announced 30 days ahead and included above.