SFTP

Published on:

Most important commands to remember

  • sftp USER@HOST — open an encrypted file-transfer session.
  • pwd / lpwd — distinguish the remote and local working directories.
  • ls -l — inspect remote entries inside the SFTP session.

Commands and flags

Command or option Meaning
-P 2222 Connect to SSH port 2222; the uppercase P matters.
student@localhost Select the test account and local server.
pwd / lpwd Show the remote / local working directory.
ls -l Request a detailed remote directory listing.
bye Close the SFTP session and return to the shell.

The second block contains commands for the sftp> prompt, not ordinary shell commands. Authentication follows your SSH configuration and may prompt for the test account password or key passphrase.

The concepts that matter

1. SFTP uses the SSH connection

SSH File Transfer Protocol performs file operations through an encrypted SSH connection. It is different from FTP protected with TLS, commonly called FTPS. Similar names do not imply interchangeable clients, ports, or server configuration.

The SSH server must offer the SFTP subsystem. A host can allow SFTP while restricting interactive shell access, and a working shell connection does not guarantee that its SFTP subsystem is configured correctly.

2. The server and user authenticate in different directions

The client checks the server’s SSH host key to establish which server it reached. The server separately authenticates the account using an allowed method such as a public key or password.

An unfamiliar host-key prompt needs comparison with a trusted fingerprint. Blind acceptance makes the identity check ineffective. A known host-key mismatch deserves investigation rather than deleting the stored key merely to make the connection succeed.

3. Local and remote paths belong to different namespaces

Inside an SFTP session, remote file commands act on the server’s visible directory tree. Local commands refer to the machine running the client. Confusing these sides is a common reason for selecting or overwriting the wrong file.

The remote view may be restricted to a dedicated directory. Its / can be the root of that restricted view, not the server’s complete filesystem. A successful session does not grant access outside the account’s permissions.

4. Transfer success and application readiness are different

SFTP supports file operations such as upload, download, and rename. A transfer can finish successfully without proving that another application has consumed the file or that its contents are semantically correct.

For automated delivery, define how a receiver recognizes a complete file and how retries avoid duplicates. Uploading under a temporary name and renaming can help when the server’s rename semantics support the design. Encryption alone supplies neither workflow coordination nor business-level deduplication.

One small example

Optional: connect to the stated test server. Check any host-key prompt against the trusted lab fingerprint before continuing. Once sftp> appears, enter the second block there, one line at a time.

sftp -P 2222 student@localhost
pwd
lpwd
ls -l
bye

Compare pwd and lpwd: they describe different machines even if the displayed paths happen to resemble each other. In ls -l, inspect names, sizes, and available permission or ownership details; exact formatting depends on client and server.

A successful listing demonstrates authenticated directory access, not write permission or completed file delivery. A subsystem error is distinct from rejected account credentials. bye closes the connection. This example deliberately lists existing entries, so there are no transferred files to remove.

Keep this idea: SFTP protects file operations with SSH, but you still need the right server identity, remote path, permissions, and delivery workflow.