如何在 SSIS 中使用脚本任务下载文件
How to download a file with a script Task in SSIS
我很难在 SSIS 脚本任务中使用 vba。基本上它从 Web 下载文件并将其保存在共享驱动器上。然后在 SQL server.I 中加载文件 尝试了代码并且它在 Excel VBA.I 中有效 为了安全目的修改了 URL。下面只是一个例子
`Const MYURL = "https://123.123.co.uk&filename=Test.xls"
Sub DataScraping()
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
objHTTP.Open "GET", MYURL, False
objHTTP.SetCredentials "1234", "1234", HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
objHTTP.Send
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write objHTTP.ResponseBody
oStream.SaveToFile ("\C\files\Test\file13 " & Format(Now(), "ddMMyyyy
HHmmss") & ".xls")
oStream.Close
End Sub'
在使用 C# 的脚本任务中:
System.Net.WebClient wc = new System.Net.WebClient();
wc.Credentials = new System.Net.NetworkCredential("1234","1234"); // user,pword
wc.DownloadFile("https://123.123.co.uk?filename=Test.xls"
,@"c:\Test"+DateTime.Now.ToString("yyyyMMdd")+".xls");
我很难在 SSIS 脚本任务中使用 vba。基本上它从 Web 下载文件并将其保存在共享驱动器上。然后在 SQL server.I 中加载文件 尝试了代码并且它在 Excel VBA.I 中有效 为了安全目的修改了 URL。下面只是一个例子
`Const MYURL = "https://123.123.co.uk&filename=Test.xls"
Sub DataScraping()
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
objHTTP.Open "GET", MYURL, False
objHTTP.SetCredentials "1234", "1234", HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
objHTTP.Send
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write objHTTP.ResponseBody
oStream.SaveToFile ("\C\files\Test\file13 " & Format(Now(), "ddMMyyyy
HHmmss") & ".xls")
oStream.Close
End Sub'
在使用 C# 的脚本任务中:
System.Net.WebClient wc = new System.Net.WebClient();
wc.Credentials = new System.Net.NetworkCredential("1234","1234"); // user,pword
wc.DownloadFile("https://123.123.co.uk?filename=Test.xls"
,@"c:\Test"+DateTime.Now.ToString("yyyyMMdd")+".xls");