Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12345»»»

No SFTP Task Component in SSIS 2005/2008? No Problem! Expand / Collapse
Author
Message
Posted Tuesday, May 11, 2010 10:26 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, August 14, 2012 1:10 PM
Points: 15, Visits: 113
awesome. this was something that I was looking for. Adding 3rd party apps to my ETL is a little mickey mouse for me.

Thank You very much.
Post #919836
Posted Tuesday, May 11, 2010 4:10 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 12:04 PM
Points: 18,064, Visits: 16,104
Nice article.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Post #920063
Posted Wednesday, May 12, 2010 3:01 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 7:13 AM
Points: 886, Visits: 617
An alternative method would be to set up a "virtual" FTP server using stunnel (www.stunnel.org) pointing to the remote sftp server, which you then connect using normal ftp uploads, and sftp handles the SSL element.
Post #920261
Posted Wednesday, May 12, 2010 7:50 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, December 18, 2014 11:18 AM
Points: 5, Visits: 61
Interesting article, but I chose a slightly different path in handling things. I am using the portable version of WinSCP, meaning there is no installation needed. They also expose Command Line arguments, meaning that all the stuff stored in the batch file is passed along as variables in the package. So I can store the variables in a database somewhere, call them when the package loads, then pass them along to the command line options. Consider the followingwritten in C#...)
  //Attaching the debugger in a 64-bit instance of SSIS will not work.

//MessageBox.Show("Attach the Debugger", "Attach the Debugger");
// TODO: Add your code here
ScriptResults TaskResult;

//jf 04132010 Created objects to hold variables set at package level
String WinSCPPath = Dts.Variables["WinSCPPath"].Value.ToString();
String WinSCPCom = Dts.Variables["WinSCPCom"].Value.ToString(); ;
String WinSCPini = Dts.Variables["WinSCPini"].Value.ToString();
String WinSCPLoggingPath = Dts.Variables["WinSCPLoggingPath"].Value.ToString();
String WinSCPLogFileName = Dts.Variables["WinSCPLogFileName"].Value.ToString();
String LoginName = Dts.Variables["LoginName"].Value.ToString();
String LoginPassword = Dts.Variables["LoginPassword"].Value.ToString();
String SiteURI = Dts.Variables["SiteURI"].Value.ToString();
String HostKey = Dts.Variables["HostKey"].Value.ToString();
String FileToPush = Dts.Variables["FileToPush"].Value.ToString();
String UploadDirectory = Dts.Variables["UploadDirectory"].Value.ToString();//UploadDirectory

//jf 04132010 Created object to hold reference for FireAgain of the FireProgress Control
bool fireAgain = false;

try
{
//jf 04132010 Attach winscp to the process within the Package
System.Diagnostics.Process winscp = new System.Diagnostics.Process();
Dts.Events.FireProgress("WinSCP process Created", 0, 0, 100, "WinSCP", ref fireAgain);

//jf 04132010 Pass variables into the Process object
//Tell the Process where to find the WinSCP object for loading
winscp.StartInfo.FileName = String.Format("{0}{1}"
, WinSCPPath
, WinSCPCom);

//Pass the location of the ini file and the logging xml file to the Process
winscp.StartInfo.Arguments = String.Format("/log={3}{1}"
, WinSCPPath
, WinSCPLogFileName
, WinSCPini
, WinSCPLoggingPath);
Dts.Events.FireProgress("Assigned Logging File", 10, 0, 100, "WinSCP", ref fireAgain);

//Do not launch a new shell "cmd" window
winscp.StartInfo.UseShellExecute = false;

//Redirect the input and output to the Logging Component
winscp.StartInfo.RedirectStandardInput = true;
winscp.StartInfo.RedirectStandardOutput = true;

//Do not show a cmd window
winscp.StartInfo.CreateNoWindow = true;

//Start the Process Thread
winscp.Start();
Dts.Events.FireProgress("WinSCP process Launched", 20, 0, 100, "WinSCP", ref fireAgain);

//Pass configuration information to WinSCP
winscp.StandardInput.WriteLine("option batch abort");
winscp.StandardInput.WriteLine("option confirm off");

//Pass Login information to WinSCP for Authentication
winscp.StandardInput.WriteLine(String.Format("open {0}:{1}@{2} -hostkey=\"{3}\""
, LoginName
, LoginPassword
, SiteURI
, HostKey));
Dts.Events.FireProgress("Remote SFTP Connection Established", 40, 0, 100, "WinSCP", ref fireAgain);

//Execute WinSCP Commands
winscp.StandardInput.WriteLine("ls");

//--change to the needed directory
winscp.StandardInput.WriteLine(String.Format("cd {0}", UploadDirectory));
Dts.Events.FireProgress("Remote SFTP File Action", 60, 0, 100, "WinSCP", ref fireAgain);

//--List the directory
winscp.StandardInput.WriteLine("ls");
//--push the file to the server
winscp.StandardInput.WriteLine(String.Format("put {0}", FileToPush));
Dts.Events.FireProgress("Process Finished", 80, 0, 100, "WinSCP", ref fireAgain);
Dts.Events.FireProgress(String.Format("put {0}", FileToPush), 0, 0, 0, "WinSCP", ref fireAgain);

//Close input to the file
winscp.StandardInput.Close();
Dts.Events.FireProgress("Remote SFTP Disconnected, WinSCP Closed", 100, 0, 100, "WinSCP", ref fireAgain);

//wait for WinSCP to Exit
winscp.WaitForExit();
MessageBox.Show(winscp.StandardOutput.ReadToEnd(), "WinSCP Output");
TaskResult = ScriptResults.Success;
}
catch (Exception e)
{
//If there is problem, fail the event and output the exception Message...
Dts.Events.FireError(999, e.Message, "WinSCP", string.Empty, 0);
TaskResult = ScriptResults.Failure;
//MessageBox.Show(e.Message);
}

Dts.TaskResult = (int)TaskResult;

Dts.TaskResult = (int)TaskResult;

Notice that we can also fire events that bubble up a message within the context of the package. This means no third party installation on the server, no batch file to be overwritten and most important of all, everything is saved in a script task in the package.
Post #920482
Posted Wednesday, May 12, 2010 8:44 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, December 17, 2014 2:02 PM
Points: 130, Visits: 946
Pretty cool.

You should submit that as an article. I did what I did because it's the only thing I could figure out.

Your way is better.
Post #920554
Posted Wednesday, May 12, 2010 8:55 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, December 18, 2014 11:18 AM
Points: 5, Visits: 61
Stan,
That wasn't my intent. I think what you have is a good article, I just don't want to come across as pithy or superior. What if we combine our content? We are both talking about the same topic. shoot me an email and let's talk about it.
Post #920574
Posted Wednesday, May 12, 2010 9:03 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, December 17, 2014 2:02 PM
Points: 130, Visits: 946
I wasn't being snarky either. I like what your way better than mine, but if I hadn't put my way out there, I would never have learned about yours.

It's synergy!
Post #920584
Posted Wednesday, May 19, 2010 1:00 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, July 29, 2014 12:33 PM
Points: 52, Visits: 201
If you don't want usernames and passwords, you can always use certificate based authentication.... Of course then, the issue with the key on the server changing becomes that much harder because now you have a client key to manage as well. I think that in a better world, this type of integration would be managed by a system that has first class support for SFTP and would allow this type of connectivity without worries such as the username and password being stored in a file in clear text... just my 1.4 cents worth.


Post #924598
Posted Thursday, June 17, 2010 10:28 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, December 1, 2014 7:36 AM
Points: 6, Visits: 53
This works great when I use it to send 1 file at a time. How can I edit it to make it loop through a list of files in a folder and send them all by the same sftp?
Post #939073
Posted Thursday, June 17, 2010 10:43 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, December 17, 2014 2:02 PM
Points: 130, Visits: 946
Basically, you would just get the list of files using this code:

http://www.thescarms.com/dotnet/listfiles.aspx

Imports System.IO

Dim strFileSize As String = ""
Dim di As New IO.DirectoryInfo("C:\temp")
Dim aryFi As IO.FileInfo() = di.GetFiles("*.txt")
Dim fi As IO.FileInfo

For Each fi In aryFi
strFileSize = (Math.Round(fi.Length / 1024)).ToString()
Console.WriteLine("File Name: {0}", fi.Name)
Console.WriteLine("File Full Name: {0}", fi.FullName)
Console.WriteLine("File Size (KB): {0}", strFileSize )
Console.WriteLine("File Extension: {0}", fi.Extension)
Console.WriteLine("Last Accessed: {0}", fi.LastAccessTime)
Console.WriteLine("Read Only: {0}", (fi.Attributes.ReadOnly = True).ToString)
Next

Instead of writing to the console, write to a 2-dimensional variable, then you just loop through them.

If this is not enough to get you there, let me know an I will try to write some custom code, but it might take a few days to find the time.
Post #939090
« Prev Topic | Next Topic »

Add to briefcase ««12345»»»

Permissions Expand / Collapse