How to Connect to an SFTP Server from Mac via Terminal

Connecting to an SFTP server from a Mac is a straightforward process, thanks to the built-in SSH client in macOS Terminal app. This guide will walk you through the steps to establish a secure file transfer session from your Mac to an SFTP server.

Interesting articles:

Here are the steps we can follow:

Step 1: Ensure SSH Access

Before starting, make sure that you have SSH access enabled on the server you’re trying to connect to. This is essential for using the SFTP protocol.  If your server allows SFTP connections, then SSH is enabled. 

Step 2: Open Terminal on Your Mac

You can find the Terminal application in the Applications > Utilities folder on your Mac. Open Terminal to begin the process.

Step 3: Connect to the SFTP Server

  1. Initiate the Connection:
    1. Type the command sftp username@server_ip in Terminal.
    2. Replace username with your actual username on the SFTP server.
    3. Replace server_ip with the IP address or domain of the SFTP server.
  2. Authenticate Your Access:
    1. Once you run the command, you’ll be prompted to enter your password. Type your password and press Enter.

Step 4: Basic File Operations

After successfully connecting, you can perform various file operations:

  • Uploading a File:
    • Use put local_file_path remote_file_path.
  • Downloading a File:
    • Use get remote_file_path local_file_path.
  • Creating a Directory on the Server:
    • Use mkdir directory_name.
  • Renaming or Moving Files:
    • Use rename old_file_path new_file_path.

Step 5: Advanced SFTP Operations

When connecting to the SFTP server through SSH, you’re able to make commands on the server to view the files and permissions you have with those files.  

  • Checking File Permissions:
    • Use ls -l file_name to view permissions.
  • Changing File Permissions:
    • Use chmod permissions_value file_name to modify permissions.

Step 6: Disconnecting from the SFTP Server

Once you have completed your file transfers, type exit to safely disconnect from the SFTP server.

Troubleshooting Common Connection Issues

If you encounter issues while connecting, check the following:

  • Ensure that your server IP and username are correct.
  • Verify that your server is configured to accept SFTP connections.
  • Check your network connection if you’re unable to connect.
  • Check to make sure you’re using the correct port.  By default, SSH and SFTP use port 22. 

By following these steps, you can easily connect to an SFTP server from your Mac using Terminal. This method provides a secure and efficient way to manage files on a remote server.