locked
Upload files to Box.com RRS feed

  • Question

  • Hi.  I need to upload/download files from Box.com, Dropbox, etc.  Is it possible to use SSIS?  If yes, please provide details on how.

    Thank you!


    newbie

    Monday, June 23, 2014 7:16 PM

Answers

  • Monday, June 23, 2014 7:20 PM
  • Yes, It is possible to do by using SSIS.

    But, we do not have any built in feature in SSIS, we can use custom code for the same.

    To achieve this, you need to use WinSCP a third party component. Download latest version of winscp. Install the exe file and place WinSCPnet.dll in C:\windows\assembly\ folder

    Take a script task and add reference to the WinSCPnet.dll and place this below code snippet in code area of script task (change the code accordingly as per your requirement):

    		public void Main()
    		{
    			string hostName = (string) Dts.Variables["User::HostName"].Value;
                string userName = (string) Dts.Variables["User::UserName"].Value;
                string password =  (string) Dts.Variables["User::Password"].Value;
                string sshHostKeyFingerprint = (string) Dts.Variables["User::SshHostKeyFingerprint"].Value;
    			
                string localoutpath = "C:\\Inbound\\";   				/* path where you want to place the downloading the file */
                string xmlfilename = "myfile.xml";						/* name of the file to be downloaded  e.g. */
                string ftpRemoteDirectory = "//Clients/xyz//";				/* remote/dropbox path from where file need to be downloaded e.g. */
                string ExecutablePath = "C:\\Program Files (x86)\\WinSCP\\WinSCP.exe";		/* path where you have installed winscp.exe executable e.g.*/
    
                
                SessionOptions sessionOptions = new SessionOptions
                {
                    Protocol = Protocol.Sftp,
                    HostName = hostName,
                    UserName = userName,
                    Password = password,
                    SshHostKeyFingerprint = sshHostKeyFingerprint
                };
     
                try
                {
                    
                    using (Session session = new Session())
                    {
                        session.ExecutablePath = ExecutablePath;
     
                        // Connect
                        session.Open(sessionOptions);
     
                        // Upload files
                        TransferOptions transferOptions = new TransferOptions();
                        transferOptions.TransferMode = TransferMode.Binary;
     
                        TransferOperationResult transferResult;
                        transferResult = session.GetFiles(ftpRemoteDirectory + xmlfilename, @"" + localOutPath + @"\", false, transferOptions);
    					 
                        // Throw on any error
                        transferResult.Check();
     
                        // Print results
                        bool fireAgain = false;
                        foreach (TransferEventArgs transfer in transferResult.Transfers)
                        {
                            Dts.Events.FireInformation(0, null, 
                                string.Format("Download of {0} succeeded", transfer.FileName),
                                null, 0, ref fireAgain);
                        }
                    }
     
                    Dts.TaskResult = (int)DTSExecResult.Success;
                }
                catch (Exception e)
                {
                    Dts.Events.FireError(0, null,
                        string.Format("Error when using WinSCP to download files: {0}", e),
                        null, 0);
        
                    Dts.TaskResult = (int)DTSExecResult.Failure;
                }
    			}

    Let me know, if will not solve your issue or any clarification here.


    Please Mark as Answer if my post solved your problem or Vote As Helpful if this helps. Blogs: www.sqlserver2005forum.blogspot.com

    • Proposed as answer by Mike Yin Monday, June 30, 2014 7:05 AM
    • Marked as answer by Mike Yin Monday, July 7, 2014 2:01 PM
    Tuesday, June 24, 2014 1:29 PM
  • this is another example of implementing WinSCP based secured FTP in SSIS

    http://visakhm.blogspot.in/2012/12/implementing-dynamic-secure-ftp-process.html


    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

    • Proposed as answer by Mike Yin Monday, June 30, 2014 7:05 AM
    • Marked as answer by Mike Yin Monday, July 7, 2014 2:01 PM
    Tuesday, June 24, 2014 1:59 PM

All replies

  • Monday, June 23, 2014 7:20 PM
  • Hi.  I need to upload/download files from Box.com, Dropbox, etc.  Is it possible to use SSIS?  If yes, please provide details on how.

    Thank you!


    newbie

    It will be custom code as there is no built in functionality. See a working code example: http://stackoverflow.com/questions/13711762/uploading-file-to-box-net

    I suspect SSIS is not ideal for these tasks, it should be left to a different interface to implement. It is not secure either to access such online resources from typically well hardened production servers.


    Arthur My Blog

    Monday, June 23, 2014 7:27 PM
  • Yes, It is possible to do by using SSIS.

    But, we do not have any built in feature in SSIS, we can use custom code for the same.

    To achieve this, you need to use WinSCP a third party component. Download latest version of winscp. Install the exe file and place WinSCPnet.dll in C:\windows\assembly\ folder

    Take a script task and add reference to the WinSCPnet.dll and place this below code snippet in code area of script task (change the code accordingly as per your requirement):

    		public void Main()
    		{
    			string hostName = (string) Dts.Variables["User::HostName"].Value;
                string userName = (string) Dts.Variables["User::UserName"].Value;
                string password =  (string) Dts.Variables["User::Password"].Value;
                string sshHostKeyFingerprint = (string) Dts.Variables["User::SshHostKeyFingerprint"].Value;
    			
                string localoutpath = "C:\\Inbound\\";   				/* path where you want to place the downloading the file */
                string xmlfilename = "myfile.xml";						/* name of the file to be downloaded  e.g. */
                string ftpRemoteDirectory = "//Clients/xyz//";				/* remote/dropbox path from where file need to be downloaded e.g. */
                string ExecutablePath = "C:\\Program Files (x86)\\WinSCP\\WinSCP.exe";		/* path where you have installed winscp.exe executable e.g.*/
    
                
                SessionOptions sessionOptions = new SessionOptions
                {
                    Protocol = Protocol.Sftp,
                    HostName = hostName,
                    UserName = userName,
                    Password = password,
                    SshHostKeyFingerprint = sshHostKeyFingerprint
                };
     
                try
                {
                    
                    using (Session session = new Session())
                    {
                        session.ExecutablePath = ExecutablePath;
     
                        // Connect
                        session.Open(sessionOptions);
     
                        // Upload files
                        TransferOptions transferOptions = new TransferOptions();
                        transferOptions.TransferMode = TransferMode.Binary;
     
                        TransferOperationResult transferResult;
                        transferResult = session.GetFiles(ftpRemoteDirectory + xmlfilename, @"" + localOutPath + @"\", false, transferOptions);
    					 
                        // Throw on any error
                        transferResult.Check();
     
                        // Print results
                        bool fireAgain = false;
                        foreach (TransferEventArgs transfer in transferResult.Transfers)
                        {
                            Dts.Events.FireInformation(0, null, 
                                string.Format("Download of {0} succeeded", transfer.FileName),
                                null, 0, ref fireAgain);
                        }
                    }
     
                    Dts.TaskResult = (int)DTSExecResult.Success;
                }
                catch (Exception e)
                {
                    Dts.Events.FireError(0, null,
                        string.Format("Error when using WinSCP to download files: {0}", e),
                        null, 0);
        
                    Dts.TaskResult = (int)DTSExecResult.Failure;
                }
    			}

    Let me know, if will not solve your issue or any clarification here.


    Please Mark as Answer if my post solved your problem or Vote As Helpful if this helps. Blogs: www.sqlserver2005forum.blogspot.com

    • Proposed as answer by Mike Yin Monday, June 30, 2014 7:05 AM
    • Marked as answer by Mike Yin Monday, July 7, 2014 2:01 PM
    Tuesday, June 24, 2014 1:29 PM
  • this is another example of implementing WinSCP based secured FTP in SSIS

    http://visakhm.blogspot.in/2012/12/implementing-dynamic-secure-ftp-process.html


    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

    • Proposed as answer by Mike Yin Monday, June 30, 2014 7:05 AM
    • Marked as answer by Mike Yin Monday, July 7, 2014 2:01 PM
    Tuesday, June 24, 2014 1:59 PM