Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

bhuro

Re: SFTP connection works in command line but it doesn't work in Powershelll

martin wrote:

Please attach a full session log file from both sessions (working and failing).

To generate log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.


Thank you for quick response. I was able to debug the issue. There was issue with Password which i have double quoted instead of single quote.

Thanks
martin

Re: SFTP connection works in command line but it doesn't work in Powershelll

Please attach a full session log file from both sessions (working and failing).

To generate log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.
bhuro

Is there anything that i missing in configuration ?
bhuro

SFTP connection works in command line but it doesn't work in Powershelll

Hi,

I am using a PowerShell version 4 to creating automating script to download the file from client SFTP.

Here is script in Powershell.I did check the SFTP connection using the same credentails in commandline and it works but when i execute following script in PowerShell ISE(Using administrator) it throwing me error (Error: Connection has been unexpectedly closed. Server sent command exit status 0.). Can someone help me to debug following code ?

try
{
# Load WinSCP .NET assembly
Add-Type -Path "c:\Program Files (x86)\WinSCP\WinSCPNet.dll"

# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "***********"
UserName = "***********"
Password = "***********"
SshHostKeyFingerprint = "*************"
}

$session = New-Object WinSCP.Session

try
{
# Connect
$session.Open($sessionOptions)

# Force binary mode transfer
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary

# Download file to the local directory d:\
# Note use of absolute path
$transferResult = $session.GetFiles("//******.Zip", "C:\users\Downloads", $False, $transferOptions)

# Throw on any error to emulate the default "option batch abort"
$transferResult.Check()
}
finally
{
# Disconnect, clean up
$session.Dispose()
}

exit 0
}
catch [Exception]
{
Write-Host ("Error: {0}" -f $_.Exception.Message)
exit 1
}