SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


No SFTP Task Component in SSIS 2005/2008? No Problem!


No SFTP Task Component in SSIS 2005/2008? No Problem!

Author
Message
albertarun
albertarun
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 Visits: 121
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.
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)SSC Guru (69K reputation)

Group: General Forum Members
Points: 69053 Visits: 18570
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

john barnett
john barnett
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1111 Visits: 750
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.
mecurioJ
mecurioJ
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 106
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 followingSadwritten 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.
Stan Kulp-439977
Stan Kulp-439977
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2563 Visits: 1150
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.
mecurioJ
mecurioJ
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 106
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.
Stan Kulp-439977
Stan Kulp-439977
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2563 Visits: 1150
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!
Mat Culpepper
Mat Culpepper
Valued Member
Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)

Group: General Forum Members
Points: 56 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.



vonda.ackerman
vonda.ackerman
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 70
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?
Stan Kulp-439977
Stan Kulp-439977
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2563 Visits: 1150
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search