question

PrietoVelisErikAbelardo-4213 avatar image
0 Votes"
PrietoVelisErikAbelardo-4213 asked ·

Deseo eliminar un archivo desde de descargar de un sftp

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
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YitzhakKhabinsky-0887 avatar image
0 Votes"
YitzhakKhabinsky-0887 answered ·

This is English speaking forum.

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



·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Monalv-msft avatar image
0 Votes"
Monalv-msft answered ·

Hi @PrietoVelisErikAbelardo-4213 ,

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.



· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @PrietoVelisErikAbelardo-4213 ,

May I know if you have anything to update?

Best regards,

Mona

0 Votes 0 ·