SSH and SFTP client library for React Native.
npm install react-native-ssh-sftp --save
yarn add react-native-ssh-sftp --save
import SSHClient from "react-native-ssh-sftp";
let client = new SSHClient("10.0.0.10", 22, "user", "password");
await client.connect();import SSHClient from "react-native-ssh-sftp";
let client = new SSHClient("10.0.0.10", 22, "user", { privateKey: "-----BEGIN RSA......" });
await client.connect();- Public key authentication also supports:
{privateKey: '-----BEGIN RSA......'}
{privateKey: '-----BEGIN RSA......', publicKey: 'ssh-rsa AAAAB3NzaC1yc2EA......'}
{privateKey: '-----BEGIN RSA......', publicKey: 'ssh-rsa AAAAB3NzaC1yc2EA......', passphrase: 'Password'}
client.disconnect();var command = "ls -l";
const output = await client.execute(command);- Supported ptyType: vanilla, vt100, vt102, vt220, ansi, xterm
var ptyType = "vanilla";
await client.startShell(ptyType);await client.on("Shell");var str = "ls -l\n";
await client.writeToShell(str);client.closeShell();await client.connectSFTP();var path = ".";
const response = await client.sftpLs(path);await client.sftpMkdir("/tmp/dirName");await client.sftpRename("/tmp/test.tar.gz", "/tmp/test1.tar.gz");await client.sftpRmdir("/tmp");await client.sftpRm("/tmp/test.tar.gz");// Download progress
client.on("DownloadProgress", (percentage) => {
console.warn(percentage);
});
const downloadedFilePath = await client.sftpDownload(
"[path-to-remote-file]",
"[path-to-local-direcotry]"
);
// Cancel download:
client.sftpCancelDownload();// Upload progress
client.on("UploadProgress", (percentage) => {
console.warn(percentage);
});
await client.sftpUpload("[path-to-local-file]", "[path-to-remote-directory]");
// Cancel upload:
client.sftpCancelUpload();client.disconnectSFTP();