I've been working on a task to upload a file to a partner's ftp site using a public PGP key in an asc file he sent me. The file looks like this (with the bulk of the key censored out):
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: PGP Desktop 10.2.1 (Build 4461)
mQEN... ... ...=K8zL
-----END PGP PUBLIC KEY BLOCK-----
I have tried several SFTP node packages, but nothing seems to be working yet. Most of the examples use a .rsa file, but all I have provided is this .asc file. From my research, I can see that some people have used files with this extension, but nobody has fully explained how.
I am able to connect to the FTP site with Filezilla and get a message that the hostkey algorithm is ssh-dss 1024 along with SHA256 and MD5 fingerprints. I'm not sure if that's helpful or not.
Does anybody have experience with .asc files and how they are used to establish an SFTP connection?
EDIT: I've tried using the npm package sftp-upload with the following code:
var SftpUpload = require('sftp-upload'), fs = require('fs');
var options = {
host:'ftp.partnersite.com',
username:'TempUserName',
path: './CSV',
remoteDir: '/',
privateKey: fs.readFileSync('pgpkeyfile.asc'),
},
sftp = new SftpUpload(options);
sftp.on('error', function(err) {
throw err;
})
.on('uploading', function(progress) {
console.log('Uploading', progress.file);
console.log(progress.percent+'% completed');
})
.on('completed', function() {
console.log('Upload Completed');
})
.upload();
On running the code, I got the following error:
Error: Unable to parse given privateKey value
which I assumes means this keyfile is in the incorrect format for sftp_upload.
As it turns out, the ASC file was not needed for the SFTP connection itself, but rather only used for encrypting the file before sending it. I was able to use the node package ssh2-sftp-client to connect to the FTP site and upload a file with the following code:
sftp.connect({
host: 'ftp.site.com',
port: '22',
username: 'myusername',
password: 'mypassword',
algorithms: {
serverHostKey: [ 'ssh-dss' ],
kex: ['diffie-hellman-group14-sha1'],
cipher: ['aes128-cbc']
}
}).then(() => {
sftp.put('./CSV/myspreadsheet.csv', '/myspreadsheet.csv', false);
}).then((data) => {
console.log(data, 'the data info');
}).catch((err) => {
console.log(err, 'catch error');
});