Original Post: I have a profile setup in WinSCP that I do not save the username and password in but does include the proxy information. I wrote a cmd application in C# that calls a text file with encrypted values. The C# then decrypts and applies the variables to a StreamWriter stdin = cmd.StandardInput. In this input I call the following:
stdin.WriteLine(WinSCPLocale + "\"{WinSCP-Profile}\" /console /command \"put -delete \"" + MPFile + "\"\" Exit /nointeractiveinput");
If I save the username and password in the profile this call works, but if I don't save the credentials in the profile then I have to send the username and password. How would I go about doing this? If I cannot pass the username and password from the decrypted values within my c# application then it becomes interactive because I have to manually enter the information. The rest of it still works, but I am trying to schedule this to run once a day withou user interaction.
Thank you,
Rick
New Post:
Figured out how I can do this. Below is the code that I am using with the variables being passed down from a decrypted string obtained from a text file:
Process cmd = new Process();
cmd.StartInfo.FileName = "cmd";
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardInput = true;
cmd.Start();
using (StreamWriter stdin = cmd.StandardInput)
{
stdin.WriteLine("WinSCP.exe \"{FOLDERNAME}/{PROFILENAME}\" /console /command");
}
System.Threading.Thread.Sleep(2000);
SendKeys.SendWait(U); --Username
System.Threading.Thread.Sleep(500);
SendKeys.SendWait("{ENTER}");
System.Threading.Thread.Sleep(2000);
SendKeys.SendWait(PW); -- Password
System.Threading.Thread.Sleep(500);
SendKeys.SendWait("{ENTER}");
SendKeys.SendWait("put " + MPFile); --put {File Path /*.*}
SendKeys.SendWait("{ENTER}");
System.Threading.Thread.Sleep(2000);
SendKeys.SendWait("EXIT");
SendKeys.SendWait("{ENTER}");
cmd.WaitForExit();
cmd.Close();
System.Threading.Thread.Sleep(5000);
string[] filePaths = Directory.GetFiles(PutFile);
foreach (string filePath in filePaths)
File.Delete(filePath); -- Delete original files