我正在尝试运行以下脚本将文件下载到文件中,
我在Windows 8上的SSDT中的脚本任务中运行它
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Globalization
Imports System.IO
Imports System.Net
Imports WinSCP
<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum
Public Sub xMain()
Try
' Setup session options
Dim sessionOptions As New SessionOptions
With sessionOptions
.Protocol = skjfslj
.HostName = "sftp.ftp.com"
.UserName = "two"
.Password = ""
.SshHostKeyFingerprint = "ssh-rsa xxxxxxxxxxxxxxxxxxxxxxxxxxx"
.SshPrivateKeyPath = ("C:\.......")
End With
Using session As Session = New Session
' Connect
session.DebugLogPath = "C:\winscp.log"
session.ExecutablePath = "C:\WinSCP.exe"
session.Open(sessionOptions)
Dim stamp As String = DateTime.Now.ToString("yyyyMMdd", CultureInfo.InvariantCulture)
Dim fileName As String = "WCCCTix_" & stamp & "_*" & ".txt"
Dim remotePath As String = "/Two/" & fileName
Dim localPath As String = "C:\Tickets\" & fileName
If session.FileExists(remotePath) Then
Dim download As Boolean
If Not File.Exists(localPath) Then
download = True
Else
Dim remoteWriteTime As DateTime =
session.GetFileInfo(remotePath).LastWriteTime
Dim localWriteTime As DateTime = File.GetLastWriteTime(localPath)
If remoteWriteTime > localWriteTime Then
download = True
Else
download = False
End If
End If
If download Then
session.GetFiles(remotePath, localPath).Check()
End If
Else
End If
session.GetFiles(remotePath, localPath).Check()
End Using
Catch e As Exception
MsgBox(String.Format("Error: {0}", e.Message))
Dts.TaskResult = ScriptResults.Failure
End Try
'Console.ReadLine()
End Sub
End Class
当我跑步时,我得到以下内容,但框中没有错误
DTS脚本任务在用户代码中遇到了一个execption
项目名称:asjdhfskjhfskjfhskjfhsd
无法加载execption的脚本
然后文本框为空,没有错误
请有人指出我正确的方向
此致
罗布