Transfer Files using SFTP In Window

In this article, I am going to learn you how you can download any file from any server, for that no software is required, just you must have root access to the remote server. There are many ways but here I am going to tell you two ways.

  1. Command Prompt
  2. Git Bash

1 Command Prompt

If you are using .pem file for security then you have to give permission for that file.

In windows put this key in a folder created under the .ssh folder


Change permission settings in Windows:

  1. File Settings > Security > Advanced
  2. Disable inheritance
  3. Convert Inherited Permissions Into Explicit Permissions
  4. Remove all the permission entries except for Administrators

OR you reset the permissions on the private key file using CMD:

Open Command Prompt (CMD) as an administrator. and run this command

icacls "C:\Users\USERNAME\.ssh\" /reset /T /C

Grant read-only permissions to the owner (you) for the private key file:

icacls "C:\Users\USERNAME\.ssh\private_key.pem" /grant:r "%USERNAME%":(R)

Make sure to replace "C:\Users\USERNAME.ssh\private_key.pem" with the correct path to your private key file.

After setting the correct permissions, try running the sftp command :

sftp -i C:\Users\USERNAME\.ssh\private_key.pem D:/local-folder/sftp/

With the proper permissions on the private key file, the “Permission denied” error should be resolved, and you should be able to connect to the SFTP server successfully.

2. Git Bash

We’ll use the OpenSSH utilities that come with Git for Windows to run the SFTP command. Here’s what you can do:

  1. Install Git for Windows: If you haven’t installed Git for Windows, you can download it from the official website and install it. During installation, make sure to select the option to include the OpenSSH utilities.
  2. Open Git Bash: After installing Git for Windows, open “Git Bash” from the Start menu.
  3. Start the SSH agent: In the Git Bash terminal, run the following command to start the SSH agent:
eval "$(ssh-agent)"

Add the private key to the agent: Now, add your private key to the SSH agent using the ssh-add command:

ssh-add "D:/path/sftp/private_amea.pem"

Check if the key is added successfully: To verify that the key is added to the agent, you can run:

ssh-add -l

Run the SFTP command: Finally, run the SFTP command without specifying the key file:

sftp D:/my_localhost/microservices/sftp/

With Git for Windows and the SSH agent, the SFTP command should now use the private key from the agent for authentication. The “bad permissions” error should be resolved, and you should be able to connect to the SFTP server securely.

Please make sure to use the correct path for the private key in the ssh-add command. If the private key is still not added to the agent or if you encounter any issues

To get All file

if you want to get all file from server folder you can use this command

sftp -i C:\Users\USERNAME\.ssh\private_key.pem D:/local-folder/sftp/
Hey folks, I'm Vivek Kumar Pandey, a software engineer with a passion for crafting elegant solutions to complex problems. From the bustling streets of Mumbai to the heart of Bangalore's tech scene, I've journeyed through the world of programming, leaving my mark one line of code at a time. Join me as I continue to explore, innovate, and push the boundaries of what's possible in the digital realm.

Related Posts

Exporting and Importing SQL Databases in phpMyAdmin Using XAMPP and Command Prompt

Managing databases is an essential task for developers and administrators alike. Whether you’re migrating data, backing up your database, or deploying updates, having the right tools and…

Mastering Cron Expressions: A Comprehensive Guide

Cron expressions are a powerful tool that enables automation and task scheduling on Unix-like operating systems. Whether you’re a systems administrator, a developer, or simply someone interested…

How to Install an SSL Certificate on a Bitnami LAMP Stack Running on CentOS 7

Securing your website with an SSL certificate is essential to protect sensitive information and build trust with your visitors. In this tutorial, we’ll guide you through the…

PrestaShop Custom Registration Field

Hello friend I am going to teach you in this tutorial that if you want to add a new field in the registration form of PrestaShop,1.7 how can…

Prestashop Webservice In Post/Put JSON Data In the body

To Post/Put data Prestashop Web service uses XML. If you want to use JSON, you need to modify Webservice and convert JSON to XML or directly JSON to data….

Leave a Reply

Your email address will not be published. Required fields are marked *