private void Run() { /* Execute PSFTP as a System.Diagnostics.Process using the supplied login info and generated batch file */ try { SecureString sec_strPassword = new SecureString(); SecureString secureString = new SecureString(); Misc miscObj = new Misc(); //Converting UnSecure String to Secure String sec_strPassword = miscObj.convertToSecureString(_Password.Trim()); ProcessStartInfo PsftpStartInfo = new ProcessStartInfo(_PsftpPath, _User.Trim() + @"@" + _Host.Trim() + @" -pw " + _Password.Trim() + @" -batch -be -b " + _BatchFilePath); /* Allows redirecting inputs/outputs of PSFTP to your app */ PsftpStartInfo.RedirectStandardInput = true; PsftpStartInfo.RedirectStandardOutput = true; PsftpStartInfo.RedirectStandardError = true; PsftpStartInfo.UseShellExecute = false; PsftpStartInfo.Domain = _Host; PsftpStartInfo.UserName = _User.Trim(); PsftpStartInfo.Password = sec_strPassword ; System.Diagnostics.Process PsftpProcess = new System.Diagnostics.Process(); PsftpProcess.StartInfo = PsftpStartInfo; <big> PsftpProcess.Start();</big> /* Streams for capturing outputs and errors as well as taking ownership of the input */ StreamReader PsftpOutput = PsftpProcess.StandardOutput; StreamReader PsftpError = PsftpProcess.StandardError; StreamWriter PsftpInput = PsftpProcess.StandardInput; while (!PsftpOutput.EndOfStream) { try { /* This is usefule for commands other than 'put' or 'get' and for catching errors. */ Outputs += PsftpOutput.ReadLine(); Outputs += PsftpError.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } PsftpOutput.Close(); PsftpError.Close(); PsftpInput.Close(); PsftpProcess.WaitForExit(); PsftpStartInfo = null; PsftpProcess = null; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } /* Delete the batch file */ try { File.Delete(_BatchFilePath); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)