1

I would like to transfer a file from my local machine to remote server using sftp in powershell.

I have used multiple ways like Open-SFTPServer, Copy-File, SFTPFileUploads, Session.put etc, however nothing worked.

Could someone help me on this?

One of the example I tried as below:

$sftp = Open-SFTPServer -serverAddress $sftpHost -userName $userName -userPassword $userPassword
David Sam
  • 59
  • 9
  • You might find [this post on SpiceWorks](https://community.spiceworks.com/topic/654445-sftp-upload-a-file-to-a-host-via-powershell) to be of interest. – Jeff Zeitlin May 19 '21 at 18:45
  • See [Upload file to SFTP using PowerShell](https://stackoverflow.com/q/38732025/850848). + If you have problems, you need to tell us more than *"nothing worked"*. – Martin Prikryl May 19 '21 at 18:52

1 Answers1

1

Windows 10 comes with OpenSSH built-in, but disabled. This contains tools like sftp, ssh, and scp:

# You may or may not need to restart after enabling the client
Add-WindowsCapability -Online -Name OpenSSH.Client

Once it's enabled, just connect as usual

# this example is interactive, and starting from powershell
PS C:\> sftp MyUser@MyServer
sftp> put test.txt
Uploading test.txt to /home/MyUser/test.txt
test.txt                                                                             100%  380    11.9KB/s   00:00
sftp> ls
test.txt
sftp> rm test.csv
Removing /home/MyUser/test.txt
sftp> quit
PS C:\> # now back in powershell
Cpt.Whale
  • 4,784
  • 1
  • 10
  • 16
  • I believe the OpenSSH client tools are built-in now in Windows 10. You do not need to enable them anyhow. Anyway, please consider posting your answer to [Upload file to SFTP using PowerShell](https://stackoverflow.com/q/38732025/850848) instead of answering this duplicate question – Martin Prikryl May 20 '21 at 05:06