PUT a built xml file using xml2js and ssh2-sftp-client in Node

23 views Asked by At

I am trying to upload a file via SFTP.

The ssh2-sftp-client module connects to the server and path fine (verified with a list request). The file I want to upload is an XML built with the xml2js module.

The PUT method returns this error:

put: Bad path: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

//create new xml file
const builder = new xml2js.Builder();
const updatedXml = builder.buildObject(updatedFeed);
console.log("file length: ", updatedXml.length);

//upload new file
const sftp = new sftpClient();
await sftp.connect({
    host: "example.com",
    port: 22,
    username: "user",
    password: "password",
});
console.log("sftp connected");
const list = await sftp.list("/web/assets/exports");
console.log(list);
await sftp.put(updatedXml, "/web/assets/exports/feed_fixed.xml");
console.log("sftp put complete");
sftp.end();
}
0

There are 0 answers