WinSCP crashes immediately when SSIS-ScriptTask is started

Advertisement

mkfromhighlands
Guest

WinSCP crashes immediately when SSIS-ScriptTask is started

Hi there,

I use WinSCPnet Assembly in SSIS-Script Task. Assembly has been installed to GAC and has been added as reference to my SSIS-Script Task. ScriptTask uses ExecutablePath property in SessionOptions.

WinSCP-Version: 5.19.5 - Automation
Windows-Version: Win 10 Enterprise v.20H2
Visual Studio 2019 - v.16.9.3

As soon as my SSIS Task starts in SSIS ControlFlow, I get the following Windows Error Popup:
WinSCP: SFTP, FTP, WebDAV, S3 and SCP client funktioniert nicht mehr. Ein Problem hat die richtige Ausführung des Programms verhindert. Schließen Sie das Programm.
*In English, this must be something like
winscp doesn't work anymore. a problem has prevented this program from running properly. close the program.
SSIS says that
Package execution completed with success.
My ScriptTask is very basic, it just has to upload files from a local directory to a FTP remote directory.

Can you please give me advice how to debug this error?

Thanks in advance,
Martin

Reply with quote

Advertisement

mkfromhighlands
Guest

WinSCP crashes immediately when SSIS-ScriptTask is started

Here´s my scripttask:
#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using WinSCP;
using System.IO;
#endregion
 
namespace ST_1138412fae60475f9346f7177723cdda
{
   [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
   public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
   {
      public void Main()
      {
            try
            {
                SessionOptions sessionOptions = new SessionOptions
                {
                    Protocol = Protocol.Ftp,
                    HostName = Dts.Variables["$Package::pHostName"].Value.ToString(),
                    UserName = Dts.Variables["$Package::pUserName"].Value.ToString(),
                    Password = Dts.Variables["$Package::pPasswort"].Value.ToString(),
                    SshHostKeyPolicy = SshHostKeyPolicy.GiveUpSecurityAndAcceptAny
                };
 
                using (Session session = new Session())
                {
                    session.ExecutablePath = Dts.Variables["$Package::pWinScpExecutablePath"].Value.ToString();
                    string sourcepath = Dts.Variables["$Package::pFolderPath"].Value.ToString();
                    string remotepath = Dts.Variables["$Package::pRemotePath"].Value.ToString();
 
                    session.Open(sessionOptions);
 
                    try
                    {
 
                        // Source-VZ einlesen
                        DirectoryInfo sdi = new DirectoryInfo(sourcepath);
                        if (sdi.GetFiles().Length == 0)
                        {
                            Console.Write("Keine Dateien zum Verarbeiten vorhanden. Abbruch.");
                        }
                        else
                        {
                            foreach (var SourceFile in sdi.GetFiles())
                            {
                                string FileToUpload = sourcepath + SourceFile.Name;
                                TransferOptions transferOptions = new TransferOptions
                                {
                                    TransferMode = TransferMode.Binary
                                };
                                TransferOperationResult transferResult;
                                transferResult = session.PutFiles(FileToUpload, remotepath + SourceFile.Name, false, transferOptions);
 
                                File.Delete(FileToUpload);
                                break;
                            }
                        }
                    }
                    catch (Exception a)
                    {
                        bool fireAgainA = false;
                        Dts.Events.FireInformation(1, "Error", string.Format("ERROR: Processing Files {0}", a), "", 0, ref fireAgainA);
                        Dts.TaskResult = (int)DTSExecResult.Failure;
                    }
 
                    session.Close();
 
                }
 
                Dts.TaskResult = (int)DTSExecResult.Success;
 
            }
            catch (Exception b)
            {
                bool fireAgainB = false;
                Dts.Events.FireInformation(1, "Error", string.Format("ERROR: WinSCP {0}", b), "", 0, ref fireAgainB);
                Dts.TaskResult = (int)DTSExecResult.Failure;
            }
 
            Dts.TaskResult = (int)ScriptResults.Success;
      }
 
        #region ScriptResults declaration
        /// <summary>
        /// This enum provides a convenient shorthand within the scope of this class for setting the
        /// result of the script.
        /// 
        /// This code was generated automatically.
        /// </summary>
        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
        #endregion
 
   }
}

Reply with quote

Advertisement

You can post new topics in this forum