Re: Unable to log onto SFTP server when using powershell script
Thanks for your feedback.
Before posting, please read how to report bug or request support effectively.
Bug reports without an attached log file are usually useless.
What do you mean by this? These characters are not encoded by WinSCP code generation for PowerShell.
Btw, did you save your script in UTF-8 encoding?
Unfortunately I haven't managed to figure out how to activate password logging in the script, only the linein order to activate logging at all. If you could tell me what I need to add to that for password logging I'd greatly appreciate it.$session.SessionLogPath = "C:\ftp\ftproot\lobko\winscp-log.txt"
Logging\LogSensitive
raw configuration option:
Though to be sure that there was no mistake, I will list the different codes that appear for the various characters in case the mistake is there:_ = not encoded by the Code Generator
€ = %E2%82%AC
! = %21
I didn't identify any difference.
Double check that the hostname and username and password match. You can enable password logging to see the real password being used. Are there any special symbols in your credentials?
Also, did you check server-side log file?
$session.SessionLogPath = "C:\ftp\ftproot\lobko\winscp-log.txt"
_ = not encoded by the Code Generator
€ = %E2%82%AC
! = %21
Can you post a log file from working GUI session for a comparison?
Ausnahme beim Aufrufen von "Open" mit 1 Argument(en): "Die Verbindung wurde unerwartet geschlossen. Der Server
sendete den Befehlsbeendigungsstatus 0.
Anmeldungsprotokoll (Siehe Sitzungsprotokoll für Details):
Verwende Benutzername "myusername".
Zugriff verweigert.
Anmeldung fehlgeschlagen."
In C:\ftp\ftproot\lobko\upload.ps1:23 Zeichen:5
+ $session.Open($sessionOptions)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SessionRemoteException
# WinSCP .NET assembly loading
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# Path to last CSV file (currently just a test file)
$file = "test_" + (Get-Date -Format dd-mm-yyyy) + "_11-25.csv"
$path = (Join-Path $PSScriptRoot $file)
# Configure session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "sftp-server-address"
UserName = "myusername"
Password = "mypassword"
SshHostKeyFingerprint = "ssh-ed25519 256 1gx2w8Rtv3wCgi7Jh8myf/KVd72cRQbow03UP8P095Q="
}
$session = New-Object WinSCP.Session
try
{
$session.SessionLogPath = "C:\ftp\ftproot\lobko\log.txt"
# Connect
$session.Open($sessionOptions)
# Transfer files
$session.PutFiles($path, "/in/Bestand/*").Check()
}
finally
{
$session.Dispose()
}
# For Debug purposes
Read-Host