我正在开发一个使用WinSCP .NET程序集将zip文件(包含多个pdf文件)上传到远程SFTP服务器的解决方案。我一直在
在记录期间发生错误,它已被关闭。
有人可以告诉我如何修复此错误。
根据这个https://gallery.technet.microsoft.com/Secure-FTP-Powershell-65a2f5c5/view/Discussions,我创建了日志文件。
以下课程是我正在使用的课程。
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);
}
答案 0 :(得分:0)
好的,所以这里不是解决这个问题的正确方法,我删除了写入错误日志文件的逻辑。获取此错误消息。仍需要弄清楚如何正确修复它。
答案 1 :(得分:0)
例外&#34;记录期间发生错误,已关闭&#34; 始终包含详细说明问题的详细信息。
最常见的原因是日志路径不存在,或者运行该进程的帐户无法写入。
WinSCP.SessionRemoteException:日志记录期间发生错误。它被关闭了。 ---&GT;
无法打开日志文件&#39; X:\ winscp.log&#39;。
系统错误。代码:2.
系统找不到指定的文件