我正在努力在SSIS脚本任务中使用下面的vba。基本上它从Web下载文件并将其保存在共享驱动器上。然后将文件加载到SQL server.I已经尝试了代码,它在Excel VBA中工作。为了安全起见,我修改了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'
答案 0 :(得分:1)
在使用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");