Topic "Passing username and password into /console"

Author Message
rhoodenpyle
[View user's profile]

Joined: 2013-04-30
Posts: 2
Location: Raliegh, NC
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
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
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
rhoodenpyle
[View user's profile]

Joined: 2013-04-30
Posts: 2
Location: Raliegh, NC
How do you use proxy without using the profile?

Thanks,

Rick

prikryl 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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
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
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License