0

This is my command that I'm trying to connect to my server from Powershell:

$mysftp = @"
$(sftp -P2222 non-root-user@myserver.icom
"SomeRandomPass"
lcd C:\Users\Saeed\Desktop\test
cd /etc/
get hostname
bye)
"@
$mysftp

There are two issues:

  1. It asks again for my password
  2. It only connects to sftp but doesn't do anything.
  3. When I run $mysftp, it only prints the values of this variable, but doesn't execute that.
  • The user is not root, so I cannot change sshd_config to use keys to connect.

How can I connect to sftp and do my commands with no password in Powershell?

My Powershell version is PSVersion 5.1.19041.3031.

iRon
  • 20,463
  • 10
  • 53
  • 79
Saeed
  • 3,255
  • 4
  • 17
  • 36
  • 2
    `sftp.exe` is an external command and not directly related to PowerShell itself. If you want to use PowerShell, you would be better of with directly invoking `.Net` classes. See e.g.: [Upload files with FTP using PowerShell](https://stackoverflow.com/a/1868367/1701026) – iRon Jul 17 '23 at 07:57

0 Answers0