I need to open XML file (create XmlDocument) without creating local copy. Using SSH.NET, I came up with this code:
var connectionInfo = new ConnectionInfo("host",
"username",
new PasswordAuthenticationMethod("username", "password"));
using (var client = new SftpClient(connectionInfo))
{
client.Connect();
System.IO.MemoryStream mem = new System.IO.MemoryStream();
client.DownloadFile("filename.xml", mem);
mem.Position=0;
using(XmlReader reader = XmlReader.Create(mem))
{
var docc = new XmlDocument();
docc.Load(mem);
}
client.Disconnect();
}
But is gets stuck on docc.Load(mem). What could be the problem?
mem object looks like this:

Note that here:
using(XmlReader reader = XmlReader.Create(mem))
{
var docc = new XmlDocument();
docc.Load(mem);
}
You are not using variable reader at all. Either change to
using(XmlReader reader = XmlReader.Create(mem))
{
var docc = new XmlDocument();
docc.Load(reader);
}
or remove reader at all:
docc.Load(mem);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With