darkoperator / Posh-SSH

PowerShell Module for automating tasks on remote systems using SSH
BSD 3-Clause "New" or "Revised" License
985 stars 227 forks source link

Copy Files from SFTP Server #195

Open Git-Renae opened 6 years ago

Git-Renae commented 6 years ago

Hello,

I am new to this site and attempting to use posh-ssh in a test environment to copy one file from windows server to another. I have successfully been able to use the code to copy a file from linux sftp server to windows but not successful windows to windows. Copy of code and errors below your assistance is appreciated.

I have gotten as far as using a domain acct to login by using -connectiontimeout parameter but when attempting to copy file I get:

``Get-SFTPFile -SessionId 0 -RemoteFile "C:\SFTPCopy\scimwebservice.txt" -LocalPath "C:\Users.admin\Documents\CopyFiles" Get-SFTPFile : Failure At line:1 char:1

When I am attempting to use a local user acct on x.x.49.202 box and from my x.x.49.1 (DC box) I've stored the password in a encrypted text file. when I attempt this code using local user acct on sftp box I am not successful even connecting ``$username= "spadmin"

$Password = Get-content "C:\Users\admin\Documents\FilesCopied\Scipts\pwd.txt" | ConvertTo-SecureString

$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $username, $Password

New-SFTPSession -ComputerName x.x.49.201" -Credential $Credential -ConnectionTimeout 120

Get-SFTPFile -SessionId 0 -RemoteFile C:\SFTPCopy\sailpointscimwebservice.txt -LocalPath C:\Users\rpinkney.admin\Documents\CopyFiles

Remove-SFTPSession -SessionId 0``

``New-SFTPSession : A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond At line:4 char:1

rmbolger commented 6 years ago

Windows doesn't have an SSH Server built-in. What SSH Server are you using?

Git-Renae commented 6 years ago

Hi @rmbolger it was setup using OpenSSH

darkoperator commented 6 years ago

will take a look at it. I guess it is the one that MS has as a Beta?

Git-Renae commented 6 years ago

Hi @darkoperator I seen some articles related to Openssh being in Beta. Not exactly sure how it was setup. I know that I can successfully connect using WinSCP but cant use the get-sftpfile cmdlets to get files from the windows server.

darkoperator commented 6 years ago

image I did a setup of the latest OpenSSH build from MS on a Win2k16 with PowerShell as the default shell and got it to work. Also through an authenticated HTTP proxy but there is a bug if there is a proxy without auth that I'm still working on