Upon opening a Session getting Error: 'System.IO.IOException' in System.Private.CoreLib.dll

Advertisement

dcflp
Joined:
Posts:
2
Location:
NZ

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:

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);
}
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.
$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)
The FTP password does have special characters, might that be causing an issue? Any help gratefully received, Thanks.
  • winSCP Error log.txt (27.99 KB, Private file)

Reply with quote

Advertisement

dcflp
Joined:
Posts:
2
Location:
NZ

Figures

Right after posting this I found a 1 character mistake in the user name I was using. The FTP upload completes now, but curiously I still get the System.IO.IOException??
Since it does not seem to affect the transfer I'll consider the case closed. But I have attached the logfile in case you are interested.
  • winSCP Error log.txt (42.34 KB, Private file)

Reply with quote

Advertisement

You can post new topics in this forum