Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
2.5k views
in .NET FTP by (180 points)
I'm having a problem with KnownHosts.LoadKnownHosts(stream). I'm writing a string that contains the correct key in the format that KnownHosts.WriteKnownHosts() creates into the stream, but no key is added to the collection.

Stream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.WriteLine(_knownHost);
writer.Flush();
_ftpConnection.KnownHosts.LoadKnownHosts(stream);
writer.Close();
stream.Close();

If I check KnownHosts.NumHosts after it's 0 and I get a SFTPException: Authentication failure, since there are no keys in the collection. Is there something I'm missing, or is there something wrong with the KnownHosts.LoadKnownHosts(stream)?

Thanks,

2 Answers

0 votes
by (162k points)
I believe there's a bug in your code - you need to set the position back to the beginning of the stream before it is passed in.

stream.Seek(0, SeekOrigin.Begin);
0 votes
by (180 points)
That worked like a charm. Thank you. :)

Regards,

Categories

...