Blog

How to Connect to an SFTP Server

Step-by-step instructions for connecting via the command line, GUI clients, and code.

Updated March 2026

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:

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
lsList files in current remote directory
cd directoryChange remote directory
put localfileUpload a file to the server
get remotefileDownload a file from the server
mkdir dirnameCreate a remote directory
rm filenameDelete a remote file
byeDisconnect

Method 2: FileZilla (Windows, macOS, Linux)

FileZilla is a free, open-source GUI client and one of the most popular SFTP tools.

  1. Download and install FileZilla Client from filezilla-project.org.
  2. Open FileZilla and go to File > Site Manager.
  3. Click New Site and set the protocol to SFTP - SSH File Transfer Protocol.
  4. Enter the hostname, port (22), and your username.
  5. Set the logon type to Normal (password) or Key file (SSH key).
  6. Click Connect.

Method 3: WinSCP (Windows)

WinSCP is a popular Windows-only SFTP client with a two-pane file manager interface.

  1. Download and install WinSCP from winscp.net.
  2. In the login dialog, set the file protocol to SFTP.
  3. Enter the hostname, port, username, and password (or browse to your private key file).
  4. Click Login.

Method 4: Cyberduck (macOS, Windows)

Cyberduck is a lightweight, user-friendly file transfer client for macOS and Windows.

  1. Download and install Cyberduck from cyberduck.io.
  2. Click Open Connection and select SFTP (SSH File Transfer Protocol).
  3. Enter the server, port, username, and password or SSH key.
  4. 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

Need an SFTP server to connect to?

SFTPHub gives you a fully managed SFTP endpoint in minutes.