Topic "SFTP without using Host Key"

Author Message
rahul.vairagi068
[View user's profile]

Joined: 2014-01-20
Posts: 4
Location: Bangalore
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);

.........
}
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
rahul.vairagi068 wrote:
but I want to do SFTP without passing argument hostkeyfingerprint

Why?

Anyway, you can use SessionOptions.GiveUpSecurityAndAcceptAnySshHostKey, but make sure you understand that you are giving up any security by doing so!
http://winscp.net/eng/docs/library_sessionoptions
_________________
Martin Prikryl
rvjhon

Guest


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
rahul.vairagi068
[View user's profile]

Joined: 2014-01-20
Posts: 4
Location: Bangalore
hi rvjhon,

I have implemented this with winscp 553 and its working fine. Please try with this version!!
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
rvjhon wrote:
$sessionOptions.GiveUpSecurityAndAcceptAnySshHostKey = "true"

I assume this is PowerShell. Afaik, the correct syntax is $true.
_________________
Martin Prikryl
Pawan Kumar

Guest


Hi,

any can tell me from where I can get SSH HOST KEY FINGERPRINT??
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
See https://winscp.net/eng/docs/faq_hostkey
_________________
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