Connecting to an SFTP server requires a hostname (or IP address), a port number (usually 22), and credentials — either a username/password combination or an SSH key. This guide covers the most common methods for connecting to an SFTP server on any platform.
What You Need Before Connecting
Before you can connect, gather the following information from your SFTP provider or server administrator:
- Hostname — The server address (e.g.,
sftp.example.com) - Port — Usually 22, but some servers use a custom port
- Username — Your SFTP account username
- Password or SSH key — Your authentication credential (SSH keys are recommended)
Method 1: Command Line (Linux, macOS, Windows)
The sftp command is built into Linux, macOS, and Windows 10+ (via OpenSSH). It is the fastest way to connect.
Connect with a password
sftp -P 22 [email protected]
You will be prompted for your password. After authenticating, you'll see the sftp> prompt.
Connect with an SSH key
sftp -i ~/.ssh/my_key -P 22 [email protected]
Common SFTP commands
| Command | Description |
|---|---|
| ls | List files in current remote directory |
| cd directory | Change remote directory |
| put localfile | Upload a file to the server |
| get remotefile | Download a file from the server |
| mkdir dirname | Create a remote directory |
| rm filename | Delete a remote file |
| bye | Disconnect |
Method 2: FileZilla (Windows, macOS, Linux)
FileZilla is a free, open-source GUI client and one of the most popular SFTP tools.
- Download and install FileZilla Client from filezilla-project.org.
- Open FileZilla and go to File > Site Manager.
- Click New Site and set the protocol to SFTP - SSH File Transfer Protocol.
- Enter the hostname, port (22), and your username.
- Set the logon type to Normal (password) or Key file (SSH key).
- Click Connect.
Method 3: WinSCP (Windows)
WinSCP is a popular Windows-only SFTP client with a two-pane file manager interface.
- Download and install WinSCP from winscp.net.
- In the login dialog, set the file protocol to SFTP.
- Enter the hostname, port, username, and password (or browse to your private key file).
- Click Login.
Method 4: Cyberduck (macOS, Windows)
Cyberduck is a lightweight, user-friendly file transfer client for macOS and Windows.
- Download and install Cyberduck from cyberduck.io.
- Click Open Connection and select SFTP (SSH File Transfer Protocol).
- Enter the server, port, username, and password or SSH key.
- Click Connect.
Method 5: Python (paramiko)
For automated transfers, Python's paramiko library provides a full SFTP implementation.
import paramiko
transport = paramiko.Transport(("sftp.example.com", 22))
transport.connect(username="myuser", password="mypassword")
sftp = paramiko.SFTPClient.from_transport(transport)
# Upload a file
sftp.put("local_file.csv", "/remote/path/file.csv")
# Download a file
sftp.get("/remote/path/file.csv", "downloaded_file.csv")
# List directory contents
for entry in sftp.listdir("/remote/path/"):
print(entry)
sftp.close()
transport.close()
Method 6: Node.js (ssh2-sftp-client)
For Node.js applications, the ssh2-sftp-client package provides a promise-based SFTP client.
const SftpClient = require("ssh2-sftp-client");
const sftp = new SftpClient();
await sftp.connect({
host: "sftp.example.com",
port: 22,
username: "myuser",
password: "mypassword",
});
// Upload a file
await sftp.put("local_file.csv", "/remote/path/file.csv");
// Download a file
await sftp.get("/remote/path/file.csv", "downloaded_file.csv");
// List directory
const list = await sftp.list("/remote/path/");
console.log(list);
await sftp.end();
Troubleshooting Connection Issues
Connection refused
Verify the hostname and port are correct. Ensure the SFTP server is running and your IP is not blocked by a firewall.
Authentication failed
Double-check your username and password. If using an SSH key, ensure the correct private key file is specified and the public key has been added to the server.
Host key verification failed
This means the server's host key has changed or is not in your known_hosts file. Verify the new key with your server administrator before accepting it.
Connection timed out
Check your network connection. Ensure port 22 (or the custom port) is not blocked by your local firewall or network.
Key Takeaways
- You need a hostname, port, username, and password or SSH key to connect to an SFTP server.
- The
sftpcommand is available on Linux, macOS, and Windows 10+. - GUI clients like FileZilla, WinSCP, and Cyberduck provide visual file management.
- Libraries like Python's paramiko and Node.js's ssh2-sftp-client enable automated SFTP in code.
- SSH key authentication is more secure than passwords and enables passwordless automation.