Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

wiglwagl

c# winscp.exe sshhostkey?

hi,

i'm using c# and the winscp.dll.

Code:
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = "sername",
UserName = "root",
Password = "123456",
SshHostKey = "ssh-rsa 4711xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
};

using (Session session = new Session())
{
// Connect
session.DisableVersionCheck = true;
session.Open(sessionOptions);

// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;

TransferOperationResult transferResult;
transferResult = session.PutFiles(@"d:\toupload\*", "/tmp/", false, transferOptions);

// Throw on any error
transferResult.Check();

// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
}
}


}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e);

}

The Problem ist, that the SshHostKey is not valid. I have to connect with winscp.exe at the fitst time, now i get the sshhostkey.

QUESTION:
Is it possible to execute the winscp.exe with host, user, pw and get back the sshkey???

Thanks a lot best regrds
ww