❓ Question
I have SFTP credentials from FileZilla (host, port, username, and password). Can I convert this to a private key and use it with jsftp
or any Node.js SFTP client?
🚫 Short Answer: No, You Cannot Convert Username/Password to a Private Key
A private key is part of an asymmetric cryptographic pair (private & public keys) used in key-based authentication, which is fundamentally different from username/password authentication.
FileZilla credentials (host, username, password) do not and cannot generate or be converted into a valid SSH private key.
🧠 Understanding the Difference
FeatureUsername/PasswordPrivate Key AuthenticationSimpler to set up✅ Yes❌ Needs key-pair setupMore secure❌ Vulnerable to leaks✅ Secure and encryptedReusable programmatically✅✅Requires private key?❌ No✅ Yes (and matching public key)
🛠️ How to Switch to Key-Based Authentication (Optional)
If you control the SFTP server or have access, you can generate a private/public key pair and use that instead.
✅ Step 1: Generate Key Pair (Locally)
bash
ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa
- This generates:
id_rsa
: your private keyid_rsa.pub
: your public key
✅ Step 2: Add Public Key to Server
Copy the contents of id_rsa.pub
into the remote server's file:
bash
~/.ssh/authorized_keys
(You'll need access to the remote server to do this.)
🚫 Why JSFTP Won’t Work Here
jsftp
is designed for FTP, not SFTP (which uses SSH under the hood). It doesn’t support:
- Secure connections over SSH
- Private key authentication
- Encrypted file transfers via SFTP
👉 Use ssh2-sftp-client
instead.
✅ Recommended: Use ssh2-sftp-client
with Private Key
Here’s how you can connect using a private key:
javascript
const Client = require('ssh2-sftp-client');
const fs = require('fs');
const sftp = new Client();
sftp.connect({
host: 'your-host.com',
port: 22,
username: 'your-username',
privateKey: fs.readFileSync('/path/to/id_rsa')
}).then(() => {
return sftp.list('/remote/path');
}).then(data => {
console.log('Directory listing:', data);
}).catch(err => {
console.error('SFTP Error:', err.message);
});
🔐 Can I Use Password Instead of Private Key?
Yes! If the server supports password authentication, you can also connect like this:
javascript
sftp.connect({
host: 'your-host.com',
port: 22,
username: 'your-username',
password: 'your-password'
})
This approach is less secure, but it works if you don’t have access to the server’s .ssh
directory to add a public key.
📁 Where Does FileZilla Store My Credentials?
- FileZilla stores saved connections in:
-
~/.config/filezilla/sitemanager.xml
(Linux/macOS) -
%APPDATA%\FileZilla\sitemanager.xml
(Windows) - ⚠️ Passwords may be stored in plaintext if you chose to remember them.
✅ Final Recommendation
ScenarioRecommendationYou have only username/passwordUse ssh2-sftp-client
with passwordYou want better securityGenerate and use SSH key pairUsing FileZilla onlyNo conversion to private keyNeed SFTP in Node.jsUse ssh2-sftp-client
(not jsftp)
🤝 Summary
- 🔐 Private keys cannot be created from SFTP usernames/passwords.
- 🔁 If you control the server, switch to key-based authentication by generating a key pair.
- ⚙️ Use
ssh2-sftp-client
for proper Node.js SFTP support, including key and password authentication.