SFTP without using Host Key

Advertisement

rahul.vairagi068
Joined:
Posts:
3
Location:
Bangalore

SFTP without using Host Key

Hi,

I am doing SFTP(uploading files) using winscp through C# code.
If I'll provide argument hostname, username, hostkeyfingerprint & privatekeyfilepath, it works!!
but I want to do SFTP without passing argument hostkeyfingerprint , it fails with error: "sessionoptions host key is not set..."

So , is it possible to do SFTP without using "hostkeyfingerprint"
If possible, could anyone please let me know, how to achieve that.

Below is part of code:
--------------------------------------------------------------
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = varHostName,
UserName = varUserName,
PortNumber = 22,
SshPrivateKeyPath = varPrivatekeyFilePath,
SshHostKeyFingerprint = ???
};
using (Session session = new Session())
{
session.ExecutablePath = varExecutablePath; //location of winscp.exe
session.Open(sessionOptions);
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;

TransferOperationResult transferResult;
transferResult = session.PutFiles(@"" + varlocalPath + "\\" + "*.txt", varRemoteOutPath, false, transferOptions);

.........
}

Reply with quote

Advertisement

rvjhon
Guest

Why i use GiveUpSecurityAndAcceptAnySshHostKey

Hi Mr,

I want use GiveUpSecurityAndAcceptAnySshHostKey
i have tested with all winscp.dll

$sessionOptions.GiveUpSecurityAndAcceptAnySshHostKey = "true"

$sessionOptions | Get-Member


TypeName: WinSCP.SessionOptions

Name MemberType Definition
---- ---------- ----------
AddRawSettings Method System.Void AddRawSettings(string setting, string value)
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
FtpMode Property WinSCP.FtpMode FtpMode {get;set;}
FtpSecure Property WinSCP.FtpSecure FtpSecure {get;set;}
HostName Property System.String HostName {get;set;}
Password Property System.String Password {get;set;}
PortNumber Property System.Int32 PortNumber {get;set;}
Protocol Property WinSCP.Protocol Protocol {get;set;}
SshHostKey Property System.String SshHostKey {get;set;}
SshHostKeyFingerprint Property System.String SshHostKeyFingerprint {get;set;}
SshPrivateKey Property System.String SshPrivateKey {get;set;}
SshPrivateKeyPath Property System.String SshPrivateKeyPath {get;set;}
SslCertificate Property System.String SslCertificate {get;set;}
SslHostCertificateFingerprint Property System.String SslHostCertificateFingerprint {get;set;}
Timeout Property System.TimeSpan Timeout {get;set;}
UserName Property System.String UserName {get;set;}


$session = New-Object WinSCP.Session

____________________________________________________________________________________________________________________________
$session | get-member


TypeName: WinSCP.Session

Name MemberType Definition
---- ---------- ----------
Failed Event WinSCP.FailedEventHandler Failed(System.Object, WinSCP.FailedEventArgs)
FileTransferred Event WinSCP.FileTransferredEventHandler FileTransferred(System.Object, WinSCP.TransferEv...
OutputDataReceived Event WinSCP.OutputDataReceivedEventHandler OutputDataReceived(System.Object, WinSCP.Outp...
Abort Method System.Void Abort()
CreateDirectory Method System.Void CreateDirectory(string path)
Dispose Method System.Void Dispose()
Equals Method bool Equals(System.Object obj)
EscapeFileMask Method string EscapeFileMask(string fileMask)
ExecuteCommand Method WinSCP.CommandExecutionResult ExecuteCommand(string command)
FileExists Method bool FileExists(string path)
GetFileInfo Method WinSCP.RemoteFileInfo GetFileInfo(string path)
GetFiles Method WinSCP.TransferOperationResult GetFiles(string remotePath, string localPath, bool r...
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ListDirectory Method WinSCP.RemoteDirectoryInfo ListDirectory(string path)
MoveFile Method System.Void MoveFile(string sourcePath, string targetPath)
Open Method System.Void Open(WinSCP.SessionOptions sessionOptions)
PutFiles Method WinSCP.TransferOperationResult PutFiles(string localPath, string remotePath, bool r...
RemoveFiles Method WinSCP.RemovalOperationResult RemoveFiles(string path)
SynchronizeDirectories Method WinSCP.SynchronizationResult SynchronizeDirectories(WinSCP.SynchronizationMode mode...
ToString Method string ToString()
AdditionalExecutableArguments Property System.String AdditionalExecutableArguments {get;set;}
DebugLogPath Property System.String DebugLogPath {get;set;}
DefaultConfiguration Property System.Boolean DefaultConfiguration {get;set;}
DisableVersionCheck Property System.Boolean DisableVersionCheck {get;set;}
ExecutablePath Property System.String ExecutablePath {get;set;}
IniFilePath Property System.String IniFilePath {get;set;}
Opened Property System.Boolean Opened {get;}
Output Property WinSCP.StringCollection Output {get;}
ReconnectTime Property System.TimeSpan ReconnectTime {get;set;}
SessionLogPath Property System.String SessionLogPath {get;set;}
Timeout Property System.TimeSpan Timeout {get;set;}
XmlLogPath Property System.String XmlLogPath {get;set;}

Now i test this 3 weeks ago!

Please help me
how use GiveUpSecurityAndAcceptAnySshHostKey ?

Can you write a few lines for use this value.

king regards
Jhon

Reply with quote

martin
Site Admin
martin avatar

Re: Why i use GiveUpSecurityAndAcceptAnySshHostKey

rvjhon wrote:

$sessionOptions.GiveUpSecurityAndAcceptAnySshHostKey = "true"
I assume this is PowerShell. Afaik, the correct syntax is $true.

Reply with quote

Advertisement

doug.thompson
Guest

SshHostKeyFingerprint not working in C#

Hi Martin
I have tried using the content of a PUB key such as sessionOptions.SshHostKeyFingerprint ="ssh-rsa AAAAB3NzaC1y..." and I just get a timeout.
I have tried to copy all the settings used in FileZilla that connect using SFTP just fine.
I have tried using sessionOptions.GiveUpSecurityAndAcceptAnySshHostKey = true; and this makes no difference.
It would be useful to have the XML comments file for your DLL, to give examples.

It would be useful to have an example of setting up an SFTP server (eg this is the PUB/Key pair created) and then what is used in the code.
I have tried SSH2 and ssh-rsa formats but no joy.

I an not that keen of reverting back to classic FTP.
Is there anyway I can use the details in FileZilla that works and use those in WinSCP?
Thanks in advance
Doug

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,390
Location:
Prague, Czechia

Re: SshHostKeyFingerprint not working in C#

doug.thompson wrote:

Hi Martin
I have tried using the content of a PUB key such as sessionOptions.SshHostKeyFingerprint ="ssh-rsa AAAAB3NzaC1y..." and I just get a timeout.
I have tried to copy all the settings used in FileZilla that connect using SFTP just fine.
I have tried using sessionOptions.GiveUpSecurityAndAcceptAnySshHostKey = true; and this makes no difference.
It would be useful to have the XML comments file for your DLL, to give examples.

It would be useful to have an example of setting up an SFTP server (eg this is the PUB/Key pair created) and then what is used in the code.
I have tried SSH2 and ssh-rsa formats but no joy.

I an not that keen of reverting back to classic FTP.
Is there anyway I can use the details in FileZilla that works and use those in WinSCP?
Thanks in advance
Doug
It's unlikely that the timeout has anything to do with host key.
Note that you can have WinSCP generate a code template based on your FileZilla settings:
https://winscp.net/eng/docs/guide_filezilla_automation
If you still have problems, start a new thread and post a complete session log file.

Reply with quote

Advertisement

You can post new topics in this forum