-1

I am trying to setup a SFTP server on AWS.

I am using ssh2-sftp-client as a client to connect to my server on AWS. I have tried this before connecting to a local server and was working successfully, the only difference now is that I am trying to use a ppk instead of a password.

I used PuttyGen to convert my pub-key into a ppk but still doesn't like it.

This is what my connection looks like:

        await sftp.connect({
            host: process.env.SFTP_HOST,
            port: process.env.SFTP_PORT,
            username: process.env.SFTP_USERNAME,
            privateKey: fs.readFileSync('./transfer_key.ppk')
        })

and this is the error I get:

 Error: ENOENT: no such file or directory, open './transfer_key.ppk'

Any idea how to connect to AWS transfer in this way?

Thank you

jarmod
  • 71,565
  • 16
  • 115
  • 122
Mario Garcia
  • 177
  • 1
  • 4
  • 15
  • 1
    Have you checked whether that file **really** exists? Also, please use proper tagging - add which programming language you are using to your question by editing – Nico Haase May 04 '21 at 15:45
  • Yes, the file really exists – Mario Garcia May 04 '21 at 15:51
  • I also used Filezilla to check the connection, and similar error FATAL ERROR: Received unexpected end-of-file from SFTP server – Mario Garcia May 04 '21 at 15:54
  • Please edit your question to contain all details. If you are not able to connect to that server using Filezilla either, this looks like a problem with the server to me - nothing you can solve in your script – Nico Haase May 04 '21 at 16:05
  • 2
    The error message implies that the key file isn't in the directory where the program is looking, or perhaps you've misspelled the filename. Try specifying the key filename as a complete, absolute path instead of a relative path. – Kenster May 04 '21 at 16:26
  • Tried that too, still it doesn't find the file. – Mario Garcia May 04 '21 at 16:48

1 Answers1

0

The error message implies it cant find the file, but maybe it means it cant find a valid file? I think your issue could be the .ppk file created by PuttyGen is the wrong kind of key file. The client is expecting a private key in "OpenSSH format", ppk files are only used with Windows applications like putty/pageant/winscp afaik.

Try loading your .ppk into puttygen, make sure the password is set and then use the Conversions menu --> Export OpenSSH key option. This creates a new text file that contains a header line, your encoded private key and a footer that would look something like this (only longer) if viewed in a text editor:

-----BEGIN RSA PRIVATE KEY-----
MIIEoQIBDIKCAQEAmnsdLEsp2hkdz+kVoCuL6JYiu5t/jUZCeaQc8TRyEeLUsk2H
0wMA8azMyzt+a1JcNa2j+jrE5Fd6UiJ7do6OQFgqLxv48QCpwNximS20yavKNCGs
5HCsP4feVq2/2/IaCMNLEcv2XBweipYyY0ME+w1wSojWwCetMw==
-----END RSA PRIVATE KEY-----
MisterSmith
  • 2,884
  • 1
  • 10
  • 13
  • Thank you for answering. So I tried that as well, but is like the file doesn't exist in the folder. I require it to try and find the path but is not there. If I can't get this to work, do you know where can I find an sftp server that doesn't require a file? – Mario Garcia May 05 '21 at 08:26
  • The library your using supports username/password - you dont have to use a key file - your only limited by the authentication methods available on the sftp sever. Personally i would advise you stick with key based authentication - its more secure than passwords. Try adding some debugging code that uses `fs.readdir` to list all the files in the directory and output them. Then you can confirm if the key file is present, named correctly etc. Post the output. https://stackoverflow.com/questions/2727167/how-do-you-get-a-list-of-the-names-of-all-files-present-in-a-directory-in-node-j – MisterSmith May 05 '21 at 16:47