Connecting to an SFTP Server
SFTP, or SSH File Transfer Protocol, encrypts both commands and data during file transfers, making it the standard replacement for unencrypted FTP. Connecting to an SFTP server requires an SFTP client, the server address, authentication credentials, and the correct port. Whether you are on Linux, macOS, or Windows, the core process is the same: establish an SSH control channel, authenticate, and then transfer files over that secure tunnel.
More from this site
Keep reading the latest coverage
Before you begin, gather the hostname or IP address of the SFTP server, the port number (default 22), your username, and the authentication method the server expects: password or SSH key pair. Some servers restrict access to specific IP ranges or require a private key protected by a passphrase, so confirm these details with your server administrator.
Connecting via Command Line
The OpenSSH suite ships with sftp on most Unix-like systems. Open a terminal and run the following:
sftp username@hostnameIf the server listens on a non-standard port, specify it with the -P flag:
sftp -P 2222 username@hostnameFor key-based authentication, point to your private key file:
sftp -i /path/to/private_key username@hostnameYou will be prompted for the passphrase if the key is encrypted, and then for the password if the server requires both a key and a password. Once connected, you are dropped into an interactive SFTP session where commands like ls, cd, put, and get let you navigate and transfer files.
Using a Graphical SFTP Client
GUI clients simplify the process for users who prefer visual file managers. Popular options include FileZilla, Cyberduck, WinSCP, and gFTP. The general connection steps are consistent across these applications:
- Open the client and locate the site manager or new connection dialog.
- Enter the protocol as SFTP, the hostname or IP, and port 22 (or the custom port).
- Supply the username and either the password or the path to your private key.
- Save the connection profile and click Connect.
- Accept the server host key on first connection if prompted.
These clients typically display the remote file system in one pane and your local files in another, allowing drag-and-drop transfers.
Connecting from Windows
Windows does not include a built-in SFTP command in the same way Unix does, though Windows 10 and 11 now ship OpenSSH client support through the Settings app. You can install the OpenSSH Client feature and use sftp in PowerShell or Command Prompt exactly as on Linux. Alternatively, WinSCP and FileZilla offer Windows-native installers with a graphical interface. For automated workflows, PowerShell can invoke sftp with a batch file of commands.
Troubleshooting Common Connection Issues
If your connection fails, verify the following:
- The server is reachable on the specified port; test with telnet hostname port or nc -zv hostname port.
- Your SSH key is in the correct format (typically PEM or OpenSSH) and matches the public key stored on the server in ~/.ssh/authorized_keys.
- Firewall rules on either side are not blocking the SFTP port.
- The server supports the key exchange or encryption algorithms your client is attempting to use.
Connection timeouts or refusals often point to network-level blocks or the SFTP service not running on the remote host. Authentication failures usually indicate a mismatched username, expired password, or an incorrect private key path.
Security Best Practices
Connect to SFTP servers using key-based authentication rather than passwords whenever possible, as keys are resistant to brute-force attacks. Protect private keys with a strong passphrase and restrict file permissions so only your user account can read them. Disable password authentication on the server side if you control the configuration, and use a non-standard port to reduce exposure to automated scans. Always verify the server host key fingerprint on first connection to prevent man-in-the-middle attacks.