如何解决WinSCP.SessionRemoteException: 给定目录不是文件! (WinSCP & SSIS)
我在 SSIS 中运行我的脚本任务时遇到一个奇怪的错误,我不明白为什么
我试图在外部 SFTP 服务器中获取最新文件,然后将其存储在我的本地环境中,在我放入 localPath
变量的目录中
明明不是文件,我介绍的是完整路径
错误信息:
Error: Error: WinSCP.SessionRemoteException: «C:\Users\Downloads» is not a file!
in WinSCP.OperationResultBase.Check()
in ST_t5fbgt5564cf3a165da70892d8c435v.ScriptMain.Main()
我的代码:
#region Namespaces
using System;
using Microsoft.SqlServer.Dts.Tasks;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Linq;
using WinSCP;
#endregion
namespace ST_t5fbgt5564cf3a165da70892d8c435v
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain :
Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public void Main()
{
try
{
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,HostName = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",UserName = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",Password = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",PortNumber = xx
};
using (Session session = new Session())
{
session.Open(sessionOptions);
const string remotePath = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const string localPath = @"C:\Users\Downloads";
RemoteDirectoryInfo directoryInfo = session.ListDirectory(remotePath);
RemoteFileInfo latest =
directoryInfo.Files
.Where(file => !file.IsDirectory)
.OrderByDescending(file => file.LastWriteTime)
.FirstOrDefault();
if (latest == null)
{
throw new Exception("No found");
}
session.GetFiles(
RemotePath.EscapeFileMask(latest.FullName),localPath).Check();
}
Dts.TaskResult = (int)DTSExecResult.Success;
}
catch (Exception e)
{
Console.WriteLine("Error: (0)",e);
return 1;
}
}
#region ScriptResults declaration
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
}
}
这是怎么回事?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。