Powershell,Posh-SSH和连接到sftp服务器

时间:2018-03-15 16:02:26

标签: powershell sftp

我试图设置一个脚本,使用密钥文件和密码短语将文件上传到sftp服务器。到目前为止,我有以下代码:

#Global variables
$sftpServer = "1.2.3.4"
$sftpDestPort = "22"
$sftpRemotePath = "/"
$sftpUsername = "UserName"

#Import the SFTP Module
Import-Module Posh-SSH

#Define the Private Key file path
$pKeyFile = "C:\ssl\key"

$nopasswd = Get-Content C:\ssl\Encrypted.txt | ConvertTo-SecureString -Key (1..16)

#Set Credetials to connect to server
$CredDest = New-Object System.Management.Automation.PSCredential($sftpUsername, $nopasswd)

#Remove any open sessions
Get-SFTPsession | Remove-SFTPSession | Out-Null

#Create SFTP Session
$Session = New-SFTPSession -ComputerName $sftpServer -Credential $CredDest -KeyFile $pKeyFile -Port $sftpDestPort

#Remove the session
Get-SFTPsession | Remove-SFTPSession

但是,当我运行它时,我一直得到的是:

New-SFTPSession : Server response does not contain SSH protocol identification.
At line:23 char:12
+ $Session = New-SFTPSession -ComputerName $sftpServer -Credential $Cre ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : SecurityError: (Renci.SshNet.SftpClient:SftpClient) [New-SFTPSession], SshConnectionException
+ FullyQualifiedErrorId : SSH.NewSftpSession

我在这里遗漏了什么吗?是否可能是Powershell有问题或sftp服务器,或其他什么?

我尝试过不同的密钥文件和密码短语。有一个“不正确的”' passphrase我得到一个不同的错误:

New-SFTPSession : DER length is '34' and cannot be more than 4 bytes.

0 个答案:

没有答案
相关问题