C# FTP Upload Server Requires OPTS 'off' - WinSCP.SessionRemoteException: Error transferring file

Advertisement

ChirpingPanda
Joined:
Posts:
2
Location:
UK

C# FTP Upload Server Requires OPTS 'off' - WinSCP.SessionRemoteException: Error transferring file

I am receiving the following exception and inner exception when attempting to upload an image to a server.

WinSCP.SessionRemoteException: Error transferring file 'c:\data\test.png'

Inner exception: WinSCP.SessionRemoteException: Copying files to remote side failed.

How my application interacts with the WinSCP library:

// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
    Protocol = Protocol.Ftp,
    HostName = this.Uri.Host,
    UserName = this.Credentials.UserName,
    Password = this.Credentials.Password,
    TimeoutInMilliseconds =300000,
};

var localFilePath = @"c:\data\test.png";
var remoteDir = @"/home/"; 

using (WinSCP.Session session = new WinSCP.Session())
{
    // Connect
    session.Open(sessionOptions);

    // Upload files
    TransferOptions transferOptions = new TransferOptions();
    transferOptions.TransferMode = TransferMode.Ascii;

    TransferOperationResult transferResult;
    transferResult = session.PutFiles(localFilePath, remoteDir, false, transferOptions);


    // Throw on any error
    transferResult.Check();

    // Print results
    foreach (TransferEventArgs transfer in transferResult.Transfers)
    {
   Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
    }
}

I have a hunch that because the server I am uploading to requires OPTS to be off (doesn't accept data in UTF8 and I have no way of changing it as other projects depend upon this setting being off) it is struggling to accept the file being uploaded. Is there any way to achieve turning OPTS off?

Reply with quote

Advertisement

ChirpingPanda
Joined:
Posts:
2
Location:
UK

Re: C# FTP Upload Server Requires OPTS 'off' - WinSCP.SessionRemoteException: Error transferring file

martin wrote:

Do you mean OPTS UTF8 ON/OFF? Do you explicitly need to send OPTS UTF8 OFF or just avoid WinSCP sending OPTS UTF8 ON?

See https://winscp.net/eng/docs/rawsettings for Utf and PostLoginCommands.

Hi prikryl, is it possible to avoid sending the OPTS command? If so, how?

Thanks.

Reply with quote

martin
Site Admin
martin avatar

Re: C# FTP Upload Server Requires OPTS 'off' - WinSCP.SessionRemoteException: Error transferring file

sessionOptions.AddRawSettings("Utf", "0");

Reply with quote

Advertisement

You can post new topics in this forum