Scenario.
i got a real time scenario like i want to download File from URL.
URL is
https://accessgudid.nlm.nih.gov/release_files/download/gudid_daily_update_20200506.zip
in the above URL for every week entire path is same except it will datetime to file name.so task is to check file is there in the given URL.if exists then download to local path.
Solution
Step1
Create two variables like RemoteUrl and LocalFolder
Step2:
take script task and add given name spaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Net;
Step3:
under public void main() add below code
public void Main()
{
// TODO: Add your code here
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
Variables varCollection = null;
Dts.VariableDispenser.LockForRead("User::RemoteUri");
Dts.VariableDispenser.LockForRead("User::LocalFolder");
Dts.VariableDispenser.GetVariables(ref varCollection);
System.Net.WebClient myWebClient = new System.Net.WebClient();
string webResource = varCollection["User::RemoteUri"].Value.ToString();
string fileName = varCollection["User::LocalFolder"].Value.ToString() + webResource.Substring(webResource.LastIndexOf('/') + 1);
myWebClient.DownloadFile(webResource, fileName);
Dts.TaskResult = (int)ScriptResults.Success;
}
See the output folder to check file is downloaded or not.
i got a real time scenario like i want to download File from URL.
URL is
https://accessgudid.nlm.nih.gov/release_files/download/gudid_daily_update_20200506.zip
in the above URL for every week entire path is same except it will datetime to file name.so task is to check file is there in the given URL.if exists then download to local path.
Solution
Step1
Create two variables like RemoteUrl and LocalFolder
Step2:
take script task and add given name spaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Net;
Step3:
under public void main() add below code
public void Main()
{
// TODO: Add your code here
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
Variables varCollection = null;
Dts.VariableDispenser.LockForRead("User::RemoteUri");
Dts.VariableDispenser.LockForRead("User::LocalFolder");
Dts.VariableDispenser.GetVariables(ref varCollection);
System.Net.WebClient myWebClient = new System.Net.WebClient();
string webResource = varCollection["User::RemoteUri"].Value.ToString();
string fileName = varCollection["User::LocalFolder"].Value.ToString() + webResource.Substring(webResource.LastIndexOf('/') + 1);
myWebClient.DownloadFile(webResource, fileName);
Dts.TaskResult = (int)ScriptResults.Success;
}
See the output folder to check file is downloaded or not.
No comments:
Post a Comment