SFTP server
SFTP server

How To connect to SFTP server from the command prompt in Windows

Learn how to connect to an SFTP server from the command prompt in Windows. This comprehensive guide will walk you through the steps to securely transfer files using the SFTP protocol, ensuring your data remains protected during the transfer process.

To connect to an SFTP server from the command prompt in Windows using an SSH private key, you can use the sftp command that comes with the OpenSSH suite. Here’s how you can do it:

  1. Ensure OpenSSH Client is Installed:
  • Windows 10 and later versions come with OpenSSH client installed by default. If it’s not installed, you can add it via the “Optional Features” in Windows settings.
  • Go to Settings > Apps > Optional features > Add a feature > OpenSSH Client > Install.
  1. Prepare Your SSH Key:
  • Make sure your SSH private key file is in a location accessible from the command prompt.
  1. Open Command Prompt:
  • Press Win + R, type cmd, and press Enter.
  1. Connect to the SFTP Server:
  • Use the following command to connect to the SFTP server:
    sh sftp -i path\to\your\private\key user@hostname
  • Replace path\to\your\private\key with the actual path to your SSH private key file.
  • Replace user with your SFTP server username.
  • Replace hostname with the IP address or hostname of the SFTP server.

Here is an example command:

sftp -i C:\Users\YourUsername\.ssh\id_rsa yourusername@ftp.example.com
  1. Interact with the SFTP Server:
  • Once connected, you can use SFTP commands to interact with the server. Some common commands include:
    • ls – List files in the current directory.
    • cd – Change directory.
    • put – Upload a file to the server.
    • get – Download a file from the server.
    • exit – Close the SFTP session.

Example Steps

  1. Open Command Prompt:
  • Press Win + R, type cmd, and hit Enter.
  1. Navigate to the Directory Containing Your Key (optional):
  • If you need to, navigate to the directory where your SSH key is stored:
    sh cd C:\Users\YourUsername\.ssh
  1. Execute the SFTP Command:
  • Run the SFTP command with the -i option pointing to your SSH key:
    sh sftp -i C:\Users\YourUsername\.ssh\id_rsa yourusername@ftp.example.com

By following these steps, you should be able to connect to your SFTP server using an SSH private key from the Windows command prompt.

Leave a Reply