keepcalculator

06 Numbers and Powers

Mac Terminal FTP SFTP Client: How to Use It

Card No. 06·65787 · Updated · Standard formula, shown below

This guide shows you how to transfer files securely between your Mac and a remote server using the built-in Terminal commands ftp and sftp. You’ll learn how to connect, navigate directories, upload and download files, and disconnect—all without installing any extra software. You only need the server’s address, your username, and your password or SSH key.

What You’ll Need

  • A Mac with Terminal (found in Applications > Utilities).
  • The hostname or IP address of the server you want to connect to.
  • Your username and password for that server (or an SSH key if using SFTP).
  • For SFTP, the server must have SSH enabled (usually port 22). For FTP, it must have an FTP service running (usually port 21).

Step-by-Step

Using SFTP (Secure File Transfer)

  1. Open Terminal – Press Cmd + Space, type “Terminal”, and hit Enter.
  2. Start an SFTP session – Type sftp username@hostname (e.g., sftp john@example.com) and press Enter. If the server uses a non-standard port (not 22), use sftp -P port username@hostname.
  3. Authenticate – Enter your password when prompted. If you have an SSH key set up, it may be used automatically. You’ll see an sftp> prompt.
  4. Navigate remote directories – Use pwd to show the current remote directory, ls to list files, and cd directory to change directories.
  5. Navigate local directories – Use lpwd for your local working directory, lls to list local files, and lcd directory to change your local directory.
  6. Upload a file – Use put localfile.txt to upload a file from your current local directory to the current remote directory. You can also use put localfile.txt remotefile.txt to rename it on the server.
  7. Download a file – Use get remotefile.txt to download it to your current local directory. Add get remotefile.txt localname.txt to save it with a different name.
  8. Transfer multiple files – Use mput *.txt to upload all .txt files, or mget *.jpg to download all .jpg files. You’ll be prompted for each file unless you use prompt to toggle off confirmations.
  9. Work with directories – Use mkdir newdir to create a remote directory, rmdir emptydir to remove an empty one, and rename old new to rename files.
  10. Exit – Type exit or quit to close the connection.

Using FTP (Unencrypted)

  1. Open Terminal – Same as above.
  2. Start an FTP session – Type ftp hostname (e.g., ftp ftp.example.com) and press Enter. If the server uses a non-standard port, use ftp hostname port.
  3. Authenticate – You’ll be asked for your username and password. If the server allows anonymous access, you can enter anonymous and your email as the password.
  4. Navigate and transfer – The commands are almost identical to SFTP: pwd, ls, cd, lcd, put, get, mput, mget, mkdir, rmdir, rename. Note that lpwd and lls are not available; use !pwd and !ls to run local commands.
  5. Exit – Type bye or quit.

Common Mistakes

  • Using SFTP commands on FTP – FTP does not support lpwd or lls. Use the ! prefix instead (e.g., !ls).
  • Forgetting the port – If the server uses a custom port, you must specify it. For SFTP, use -P (capital P); for FTP, just add the port after the hostname.
  • Assuming SFTP and FTPS are the same – SFTP is over SSH (port 22), while FTPS is FTP over TLS/SSL (usually port 990). The sftp command cannot connect to an FTPS server. Use a dedicated client for FTPS.
  • Uploading to the wrong directory – Always check pwd before uploading. You might be in the root directory instead of your web root.
  • Binary vs. text mode – FTP has a default mode that can corrupt files. Use binary before transferring images, archives, or executables. SFTP handles this automatically.
  • Typing the password wrong – Terminal does not show any characters when you type your password. It’s easy to mistype; press Enter and try again if you get an authentication error.

Tips

  • Use SFTP whenever possible – FTP sends your password and data in plain text, which can be intercepted. SFTP encrypts everything.
  • Set up SSH keys – For SFTP, you can avoid typing your password every time by generating an SSH key pair and adding the public key to the server’s ~/.ssh/authorized_keys file.
  • Use tab completion – In both SFTP and FTP, you can press Tab to autocomplete file and directory names (if the server supports it).
  • Create a batch file – You can put SFTP commands in a text file and run sftp -b batchfile username@hostname to execute them automatically.
  • Check your local path – Before downloading, use lpwd (SFTP) or !pwd (FTP) to know where files will land.
  • Resume interrupted transfers – In SFTP, use reget to resume a download and reput to resume an upload. FTP has reget as well.

Troubleshooting

  • “Connection refused” – The server may not be running the service or the port is blocked. Double-check the hostname and port. For SFTP, ensure SSH is enabled; for FTP, ensure the FTP service is running.
  • “Host key verification failed” – This happens when the server’s key has changed. If you trust the server, remove the old key with ssh-keygen -R hostname and try again.
  • “Permission denied” – Your username or password is wrong, or your account lacks access to the target directory. Verify credentials and check directory permissions.
  • File transfer stalls or times out – This could be a firewall or network issue. Try passive mode for FTP by typing passive at the FTP prompt. For SFTP, try using a different port if the server supports it.
  • “Command not found” – If sftp or ftp is not recognized, you may be in a restricted shell. Use the full path /usr/bin/sftp or /usr/bin/ftp.
  • FTP shows “Not connected” – You may have been disconnected due to inactivity. Type open hostname to reconnect, or restart the session.

Frequently Asked Questions

What is the difference between FTP and SFTP?

FTP (File Transfer Protocol) is unencrypted, while SFTP (SSH File Transfer Protocol) runs over SSH and encrypts both your login and your data. SFTP is more secure and generally recommended.

Can I use SFTP to connect to a regular FTP server?

No. SFTP requires the server to have SSH enabled. If the server only supports FTP, you must use the ftp command or a client that supports FTPS (FTP over SSL) if the server offers it.

How do I upload an entire folder?

SFTP and FTP commands do not have a built-in recursive upload. You can use put -r foldername in SFTP (if supported) or use mput with a wildcard for files. For a true recursive transfer, consider using scp -r or a graphical client.

Why does my file get corrupted after transfer?

This often happens with FTP when transferring binary files (like images or zip files) in ASCII mode. Type binary before transferring. SFTP automatically handles binary correctly.

How do I see what’s in my local directory while connected?

In SFTP, use lls and lpwd. In FTP, use !ls and !pwd.

Can I use Terminal to transfer files to a cloud storage service?

Only if that service provides an SFTP or FTP endpoint. Many cloud services do not, but some (like certain web hosts) do. For others, you may need to use their own CLI tools or APIs.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →