Upon opening a Session getting Error: 'System.IO.IOException' in System.Private.CoreLib.dll
Issue looks to be similar to https://winscp.net/forum/viewtopic.php?t=11184.
I'm using the suggested code for uploading a file via FTP:
I've attached the output log. A quick look through suggests the connection is getting refused, though I'm using much the same setting as for a PowerShell script that works.
The FTP password does have special characters, might that be causing an issue? Any help gratefully received, Thanks.
I'm using the suggested code for uploading a file via FTP:
try { //configure session options SessionOptions sessionOptions = new SessionOptions { Protocol = Protocol.Sftp, HostName = settingsModel.FtpSettings.HostName, UserName = settingsModel.FtpSettings.UserName, Password = settingsModel.FtpSettings.Password, PortNumber = int.Parse(settingsModel.FtpSettings.PortNumber), SshHostKeyPolicy = SshHostKeyPolicy.GiveUpSecurityAndAcceptAny }; using (Session session = new Session()) { session.DebugLogPath = "winSCP Error log.txt"; // Connect session.Open(sessionOptions); // Upload files TransferOptions transferOptions = new TransferOptions(); transferOptions.TransferMode = TransferMode.Binary; TransferOperationResult transferResult; transferResult = session.PutFiles(filepath, settingsModel.FtpSettings.FtpDirectoryPath, false, transferOptions); // Throw on any error transferResult.Check(); // Print results foreach (TransferEventArgs transfer in transferResult.Transfers) { Console.WriteLine("Upload of {0} succeeded", transfer.FileName); } } } catch (Exception e) { Console.WriteLine("Error: {0}", e); }
$sessionOptions = New-Object -TypeName WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Sftp HostName = 'cloud.xxx' UserName = 'xxx' Password = 'xxx' PortNumber = 22 GiveUpSecurityAndAcceptAnySshHostKey = $true} $session = [WinSCP.Session]::new() $session.Open($sessionOptions)