Passing username and password into /console

Advertisement

rhoodenpyle
Joined:
Posts:
2
Location:
Raliegh, NC

Passing username and password into /console

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

Reply with quote E-mail

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
28,316
Location:
Prague, Czechia

Re: Passing username and password into /console

You should better not use profile, but specify your complete session settings (including username and password) on command-line.

Or even better, use WinSCP .NET assembly:
https://winscp.net/eng/docs/library
_________________
Martin Prikryl

Reply with quote

rhoodenpyle
Joined:
Posts:
2
Location:
Raliegh, NC

Re: Passing username and password into /console

How do you use proxy without using the profile?

Thanks,

Rick

martin wrote:

You should better not use profile, but specify your complete session settings (including username and password) on command-line.

Or even better, use WinSCP .NET assembly:
https://winscp.net/eng/docs/library

Reply with quote E-mail

martin
Site Admin
martin avatar
Joined:
Posts:
28,316
Location:
Prague, Czechia

Re: Passing username and password into /console

rhoodenpyle wrote:

How do you use proxy without using the profile?
Please read documentation:
https://winscp.net/eng/docs/rawsettings

If that does not help, come back.
_________________
Martin Prikryl

Reply with quote

Advertisement

You can post new topics in this forum