Tuesday, December 6, 2011

SFTP + SSIS

We had a requirement to work on SSIS package uploading files to SFTP location . Unfortunately SSIS doesn't support SFTP , so we looked around a couple of free SSIS addons which didn't work. Then i finally ended up installing winscp client on machine & used there scripting language  for .Net in to the script component task .


Code to use :

     Process winscp = new Process();
            winscp.StartInfo.FileName = @"C:\Program Files (x86)\WinSCP\winscp.com";
            winscp.StartInfo.Arguments = "/log=\"" + logname + "\"";
            winscp.StartInfo.UseShellExecute = false;
            winscp.StartInfo.RedirectStandardInput = true;
            winscp.StartInfo.RedirectStandardOutput = true;
            winscp.StartInfo.CreateNoWindow = true;
            winscp.Start();

            // Feed in the scripting commands
            winscp.StandardInput.WriteLine("option batch on");
            winscp.StandardInput.WriteLine("option confirm off");
            winscp.StandardInput.WriteLine("open sftp://username:password@sftp-server-name:portno");
            winscp.StandardInput.WriteLine("ls");
            winscp.StandardInput.WriteLine("put   d:\test.txt " );
            winscp.StandardInput.Close();

            // Collect all output (not used in this example)
            string output = winscp.StandardOutput.ReadToEnd();

            // Wait until WinSCP finishes
            winscp.WaitForExit();

-------------

That's all , Isn't it  so Simple ?   Lol..  Hope this helps.

Enjoy



No comments:

Post a Comment