{ console.log("ready!"); conn.exec(`scp -t ${remoteFile}`, (err, stream) => { if (err) throw err; stream .on("close", () => { console.log(`Local file ${localFile} copied to ${remoteFile}`); conn.end(); }) .on("data", (data) => { if (data.toString() === "C") { stream.write(`0644 ${localFile.split("/").pop()}\n`); } else if (data.toString() === "D") { stream.write("E\n"); } else { stream.end(); } }) .stderr.on("data", (dataErr) => { console.error(dataErr.toString()); conn.end(); }); stream.write( `C0644 ${fs.statSync(localFile).size} ${localFile.split("/").pop()}\n` ); fs.createReadStream(localFi"> { console.log("ready!"); conn.exec(`scp -t ${remoteFile}`, (err, stream) => { if (err) throw err; stream .on("close", () => { console.log(`Local file ${localFile} copied to ${remoteFile}`); conn.end(); }) .on("data", (data) => { if (data.toString() === "C") { stream.write(`0644 ${localFile.split("/").pop()}\n`); } else if (data.toString() === "D") { stream.write("E\n"); } else { stream.end(); } }) .stderr.on("data", (dataErr) => { console.error(dataErr.toString()); conn.end(); }); stream.write( `C0644 ${fs.statSync(localFile).size} ${localFile.split("/").pop()}\n` ); fs.createReadStream(localFi"> { console.log("ready!"); conn.exec(`scp -t ${remoteFile}`, (err, stream) => { if (err) throw err; stream .on("close", () => { console.log(`Local file ${localFile} copied to ${remoteFile}`); conn.end(); }) .on("data", (data) => { if (data.toString() === "C") { stream.write(`0644 ${localFile.split("/").pop()}\n`); } else if (data.toString() === "D") { stream.write("E\n"); } else { stream.end(); } }) .stderr.on("data", (dataErr) => { console.error(dataErr.toString()); conn.end(); }); stream.write( `C0644 ${fs.statSync(localFile).size} ${localFile.split("/").pop()}\n` ); fs.createReadStream(localFi">
const Client = require("ssh2").Client;
const fs = require("fs");

const localFile = "/PATH/abc";
const remoteFile = "/tmp/ppppp.pcm";

const conn = new Client();

conn
  .on("ready", () => {
    console.log("ready!");
    conn.exec(`scp -t ${remoteFile}`, (err, stream) => {
      if (err) throw err;
      stream
        .on("close", () => {
          console.log(`Local file ${localFile} copied to ${remoteFile}`);
          conn.end();
        })
        .on("data", (data) => {
          if (data.toString() === "C") {
            stream.write(`0644 ${localFile.split("/").pop()}\\n`);
          } else if (data.toString() === "D") {
            stream.write("E\\n");
          } else {
            stream.end();
          }
        })
        .stderr.on("data", (dataErr) => {
          console.error(dataErr.toString());
          conn.end();
        });
      stream.write(
        `C0644 ${fs.statSync(localFile).size} ${localFile.split("/").pop()}\\n`
      );
      fs.createReadStream(localFile).pipe(stream);
    });
  })
  .connect({
    host: "123.123.123.123",
    port: 123,
    username: "root",
    password: "abc",
  });