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)
- Open Terminal – Press
Cmd + Space, type “Terminal”, and hit Enter. - 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), usesftp -P port username@hostname. - 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. - Navigate remote directories – Use
pwdto show the current remote directory,lsto list files, andcd directoryto change directories. - Navigate local directories – Use
lpwdfor your local working directory,llsto list local files, andlcd directoryto change your local directory. - Upload a file – Use
put localfile.txtto upload a file from your current local directory to the current remote directory. You can also useput localfile.txt remotefile.txtto rename it on the server. - Download a file – Use
get remotefile.txtto download it to your current local directory. Addget remotefile.txt localname.txtto save it with a different name. - Transfer multiple files – Use
mput *.txtto upload all .txt files, ormget *.jpgto download all .jpg files. You’ll be prompted for each file unless you usepromptto toggle off confirmations. - Work with directories – Use
mkdir newdirto create a remote directory,rmdir emptydirto remove an empty one, andrename old newto rename files. - Exit – Type
exitorquitto close the connection.
Using FTP (Unencrypted)
- Open Terminal – Same as above.
- Start an FTP session – Type
ftp hostname(e.g.,ftp ftp.example.com) and press Enter. If the server uses a non-standard port, useftp hostname port. - Authenticate – You’ll be asked for your username and password. If the server allows anonymous access, you can enter
anonymousand your email as the password. - Navigate and transfer – The commands are almost identical to SFTP:
pwd,ls,cd,lcd,put,get,mput,mget,mkdir,rmdir,rename. Note thatlpwdandllsare not available; use!pwdand!lsto run local commands. - Exit – Type
byeorquit.
Common Mistakes
- Using SFTP commands on FTP – FTP does not support
lpwdorlls. 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
sftpcommand cannot connect to an FTPS server. Use a dedicated client for FTPS. - Uploading to the wrong directory – Always check
pwdbefore 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
binarybefore 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_keysfile. - 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@hostnameto 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
regetto resume a download andreputto resume an upload. FTP hasregetas 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 hostnameand 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
passiveat the FTP prompt. For SFTP, try using a different port if the server supports it. - “Command not found” – If
sftporftpis not recognized, you may be in a restricted shell. Use the full path/usr/bin/sftpor/usr/bin/ftp. - FTP shows “Not connected” – You may have been disconnected due to inactivity. Type
open hostnameto 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
- Compressed Zipped Folder Access Denied? Fix It
- IPTV TV Boxes: How to Choose the Right Streaming Device
- Custom Races in Assetto Corsa: Server Setup Guide
- Dueling Grounds Events Schedule: Full Guide
- Evaluating Co-Packaged Optics Switches for AI Data Centers
- RTX 5080 Best Settings for 1440p & 4K Gaming