.net - WinSCP .NET 程序集 - 记录期间发生错误。已关闭

标签 .net error-handling sftp winscp winscp-net

我正在开发一个解决方案,使用 WinSCP .NET 程序集将 zip 文件(包含多个 pdf 文件)上传到远程 SFTP 服务器。我不断得到

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

谁能告诉我如何修复这个错误。

根据这个https://gallery.technet.microsoft.com/Secure-FTP-Powershell-65a2f5c5/view/Discussions ,我已经创建了日志文件。

以下类(class)是我正在使用的类(class)。

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);
}

最佳答案

异常“日志记录期间发生错误,已关闭”始终包含详细说明问题的更多信息。

最常见的原因是日志路径不存在,或者运行进程的帐户不可写入。

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

关于.net - WinSCP .NET 程序集 - 记录期间发生错误。已关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31105695/

相关文章:

c# - 从 C# 中的 App.config 文件中读取 key

list - 如何用Erlang重写列表?

java - 将 .txt 文件导出到 sFTP 服务器后,换行符不起作用

ssh - 连接失败。用尽了可用的身份验证方法

wordpress - LEMP + wordpress 文件权限能够编辑、升级和使用 sftp 客户端

c# - 随机生成数字 1 的次数超过 90%

.net - WinForms 应用程序中的自定义标题栏/镶边

c# - 将字符串中的小时和分钟添加到日期时间

php - 直接输入没有搜索关键字的网址时,如何解决错误?

python - CommandOnCooldown 错误处理程序未捕获错误!已经测试了一切