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

martin

Re: Figures

There's no IOException in the log. If you want to pursue this, please post complete exception stacktrace.
dcflp

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.
dcflp

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.