Deseo eliminar un archivo desde de descargar de un sftp

Prieto Velis, Erik Abelardo 1 Reputation point
2021-03-04T21:00:30.057+00:00

Estimado tengo el siguiente codigo que me permite conectarme a un sftp a traves de un ssis pero no se como eliminar el archivo despues de descargar tendran o conceran alguna forma. // Cree un nuevo objeto de proceso para ejecutar WinSCP Process winscp = new Process(); // Establecer la ruta ejecutable y el directorio de descarga winscp.StartInfo.FileName = Dts.Variables["$Package::pWinSCPLocation"].Value.ToString(); winscp.StartInfo.WorkingDirectory = Dts.Variables["$Package::pDownloadDir"].Value.ToString(); // Establecer opciones de ejecución estática (no es necesario cambiarlas) winscp.StartInfo.UseShellExecute = false; winscp.StartInfo.RedirectStandardInput = true; winscp.StartInfo.RedirectStandardOutput = true; winscp.StartInfo.CreateNoWindow = true; // Establecer opciones de sesión string sessionOptionString = "option batch abort" + System.Environment.NewLine + "option confirm off"; // Construya la cadena de conexión (<usuario>: <contraseña> @ <nombre de host>) string connectString = @"open " + Dts.Variables["$Package::pServerUserName"].Value.ToString() + ":" + Dts.Variables["$Package::pServerUserPassword"].GetSensitiveValue().ToString() + "@" + Dts.Variables["$Package::pServerName"].Value.ToString(); // El suministro de la clave de host agrega un nivel adicional de seguridad y evita que se le solicite que confíe en el servidor. string hostKeyString = Dts.Variables["$Package::pServerHostKey"].Value.ToString(); // If hostkey was specified, include it if (hostKeyString != null && hostKeyString.Length > 0) connectString += " -hostkey=\"" + hostKeyString + "\""; // Construye la cadena de comando get string getString = "get " + Dts.Variables["$Package::pFilename"].Value.ToString(); // Cree variables de salida para capturar información de ejecución string outStr = "", errStr = ""; int returnVal = 1; // Este bloque try / catch capturará fallas catastróficas (como especificar la ruta incorrecta a winscp). try { winscp.Start(); winscp.StandardInput.WriteLine(sessionOptionString); winscp.StandardInput.WriteLine(connectString); winscp.StandardInput.WriteLine(getString); winscp.StandardInput.Close(); // Establezca outStr en el valor de salida, ofuscando la contraseña outStr = winscp.StandardOutput.ReadToEnd().Replace(":" + Dts.Variables["$Package::pServerUserPassword"].GetSensitiveValue().ToString() + "@", ":*******@"); // Espere a que salga la aplicación winscp.WaitForExit(); returnVal = winscp.ExitCode; } catch (Exception ex) { errStr = "An error occurred when attempting to execute winscp.com: " + ex.Message.Replace("'", "\"").Replace("—", " – "); } // Variable de no hacer nada requerida para FireInformation a continuación bool fireagain = true; // Registro de salida en registro SSIS if (returnVal != 0 || errStr.Length > 0) // Error { if (errStr.Length > 0) Dts.Events.FireError(0, "WinSCP Exception", errStr.Replace("'", "\"").Replace("—", " – "), "", 0); if (outStr.Length > 0) Dts.Events.FireError(0, "WinSCP error", "A WinSCP error has occurred. The full output stack follows: " + outStr.Replace("'", "\"").Replace("—", " – "), "", 0); } else // No error Dts.Events.FireInformation(0, "WinSCP output", outStr, string.Empty, 0, ref fireagain); Dts.TaskResult = (returnVal != 0) ? (int)ScriptResults.Failure : (int)ScriptResults.Success;

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,451 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Yitzhak Khabinsky 24,941 Reputation points
    2021-03-04T21:42:39.577+00:00

    This is English speaking forum.

    Overall, you can use WinSCP RemoveFile() method to delete a file.
    Here is its documentation: library_session_removefile

    0 comments No comments

  2. Monalv-MSFT 5,891 Reputation points
    2021-03-05T02:12:39.597+00:00

    Hi @Prieto Velis, Erik Abelardo ,

    Please use Execute Process Task to delete the file.

    Please refer to Using SFTP with SQL Server Integration Services.

    Best regards,
    Mona

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.