C#- Renci.Ssh.Net- Which one gives optimized performance- WriteAllText Vs. UploadFile
I need to generate multiple XML files at SFTP location from C# code. for SFTP connectivity, I am using Renci.Ssh.net. I found there are different methods to generate files including WriteAllText()
and UploadFile()
. I am producing XML string runtime, currently I've used WriteAllText()
method (just to avoid creating the XML file on local and thus to avoid IO operation).
using (SftpClient client = new SftpClient(host,port, sftpUser, sftpPassword))
{
client.Connect();
if (client.IsConnected)
{
client.BufferSize = 1024;
var filePath = sftpDir + fileName;
client.WriteAllText(filePath, contents);
client.Disconnect();
}
client.Dispose();
}
Will using UploadFile()
, either from FileStream
or MemoryStream
give me better performance in long run?
The result document size will be in KB, around 60KB.
Thanks!
SftpClient.UploadFile
is optimized for uploads of large amount of data.
But for 60KB, I'm pretty sure that it makes no difference whatsoever. So you can continue using the more convenient SftpClient.WriteAllText
.
Though, I believe that most XML generators (like .NET XmlWriter
are able to write XML to Stream
(it's usually the preferred output API, rather than a string). So the use of SftpClient.UploadFile
can be more convenient in the end.
See also What is the difference between SftpClient.UploadFile and SftpClient.WriteAllBytes?