WinSCP .NET assembly - Error occurred during logging. It's been turned off

I am developing a solution that uses WinSCP .NET assembly to upload zip file (contains multiple pdf files) to the remote SFTP server. I am keep getting

Error occurred during logging, it's been turned off.

Could anyone please tell me how to fix this error.

According to this https://gallery.technet.microsoft.com/Secure-FTP-Powershell-65a2f5c5/view/Discussions , I have created the log file.

The following class is the one that I am using.

public class PSftp
{
    public void PutFile(string localfile)
    {
        //Send Ftp Files - same idea as above - try...catch and try to repeat this code 
        //if you can't connect the first time, timeout after a certain number of tries. 
        var sessionOptions = new SessionOptions
        {
            Protocol = Protocol.Sftp,
            HostName = ConfigurationManager.AppSettings["sFTPhost"],
            UserName = ConfigurationManager.AppSettings["sFTPuid"],
            Password = ConfigurationManager.AppSettings["sFTPpwd"],
            PortNumber = int.Parse(ConfigurationManager.AppSettings["sFTPport"]),
            SshHostKeyFingerprint = ConfigurationManager.AppSettings["sFTPhostkey"]

        };

        using (var session = new Session())
        {
            session.SessionLogPath = ConfigurationManager.AppSettings["sFTPlogPath"];
            session.DisableVersionCheck = false;
            session.DefaultConfiguration = false;
            session.Open(sessionOptions); //Attempts to connect to your sFtp site
            //Get Ftp File
            var transferOptions = new TransferOptions
            {
                TransferMode = TransferMode.Binary,
                FilePermissions = null,
                PreserveTimestamp = false
            };
            //<em style="font-size: 9pt;">Automatic, Binary, or Ascii  
            //null for default permissions.  Can set user, 
            //Group, or other Read/Write/Execute permissions. 
            //destination file to that of source file - basically change the timestamp 
            //to match destination and source files.   
            transferOptions.ResumeSupport.State = TransferResumeSupportState.Off;


            //the parameter list is: local Path, Remote Path, Delete source file?, transfer Options  
            TransferOperationResult transferResult = session.PutFiles(localfile, ConfigurationManager.AppSettings["sFTPInboxPath"], false, transferOptions);
            //Throw on any error 
            transferResult.Check();
            //Log information and break out if necessary
        };

    }
}

//How to use the above class
public void SaveFiletoFtp(string source)
{
    var pftp = new PSftp();
    pftp.PutFile(source);
}

Answers


The exception "Error occurred during logging, it's been turned off" always includes more information that details the problem.

The most common cause is that the log path does not exist, or is not writable by the account that run the process.

WinSCP.SessionRemoteException: Error occurred during logging. It's been turned off. ---> Can't open log file 'X:\winscp.log'. System Error. Code: 2. The system cannot find the file specified


Okay, so here is not really the right solution to this problem, I remove the logic that write into the error log file. Get ride of this error message. Still need to figure out how to fix it properly though.


Need Your Help

What is a current analog of COM technology?

c# .net wpf com

COM technology seems a little outdated already, though still in use. But what approach is recommended now for implementing the same kind of interoperability when building a .NET app, specifically, ...

How to encode CR LF in DataSet.WriteXML?

c# .net xml dataset

I am using DataSet.ReadXML and DataSet.WriteXML to read and update an XML file. In some places I have a text column that may contain carriage return, linefeed (&amp;#13;&amp;#10;)