avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Sunday May 19, 2024, 11:02 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: CMD SFTP from Windows syntax  (Read 1872 times)


  • Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 1,824
    • View Profile
    • Donate to Member
CMD SFTP from Windows syntax
« on: June 23, 2022, 12:42 PM »

I want to sftp a file to a server using a public key.
I have stored the key in my desktop but I get an error:

CreateProcessW failed error:2
posix_spawn: No such file or directory

Can anyone tell me please the right syntax to send a C:\file.txt to using C:\publickey.pkk ?

CMD sftp usage:
usage: sftp [-46aCfpqrv] [-B buffer_size] [-b batchfile] [-c cipher]
          [-D sftp_server_path] [-F ssh_config] [-i identity_file]
          [-J destination] [-l limit] [-o ssh_option] [-P port]
          [-R num_requests] [-S program] [-s subsystem | sftp_server]

PS: I cannot install anything on the machine



  • Member
  • Joined in 2006
  • **
  • Posts: 2,924
    • View Profile
    • Donate to Member
Re: CMD SFTP from Windows syntax
« Reply #1 on: June 23, 2022, 03:20 PM »
A graphical client, like FileZilla, is out of the question? Or WinSCP, which can be used as a graphical client, but also through the command-line?

The Windows command line is usually not that great for file transfers with FTP.

Side note: is a domain that gets forwarded to the website of, a company that provides (S)FTP servers on Azure, AWS and also on-premise.

Anyway, command line (S)FTP clients mostly require a text file that contains the file names to be transported. But also your login information.

For example:
you create a file, called: files_to_transport_with_sftp.txt
In that file you add a line that opens the connection, like so:
open sftp://user:[email protected]/ -hostkey="ssh-rsa 2048 xxxxxxxxxxx..."

You will need to fill in the content of your 'publickey.pkk' file where the 'xxxxxxxxxxx...' are shown in parameter '-hostkey'. You are likely needing to change the 'ssh-rsa 2048' part as well, with what was used to generate your key.

The next line in the files_to-transport_with_sftp.txt should be something similar as:
put C:\<path>\<to>\<your>\file.txt

On the destination FTP server your user account will have a default folder assigned. The line above will store the file into that default folder.

The next line in the files_to-transport_with_sftp.txt has to be:

You need to tell the FTP server to close the connection.

The final line in the files_to-transport_with_sftp.txt has to be:

You'll need to exit the sftp software and give control back to the command-line interpreter you are about to use to start the FTP session.

In the command-line interpreter, you can now use the line:
sftp -b <path>\<to>\files_to-transport_with_sftp.txt

Why use the batch file method? You can generate such files pretty easily execute them and then remove them (or keep them around for auditing purposes, if that is something to you). The separate generation of such files makes FTP transfers easier/simpler/more secure. And much more fit for automatization. However, the above also should show you that any form of FTP transfers are severely outdated by now. And other methods of file transfers, like WebDAV, are much more secure and most of the time dramatically faster.
« Last Edit: June 23, 2022, 03:41 PM by Shades »