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?
€
are all broken. The !
and _
work just fine with the UTF-8 encoding.
€
signs show up properly in the log again. Incidentally, now the connection could also be established finally and the upload worked flawlessly.
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
$session.SessionLogPath = "C:\ftp\ftproot\lobko\winscp-log.txt"
_
€
and !
.
_ = not encoded by the Code Generator
€ = %E2%82%AC
! = %21
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
_
€
and !
). In order to get the encoded version of the password, I copied it from the result the GUI Code Generator gives me when I select "Script" rather than "PowerShell".
# 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