Skip to content

Instantly share code, notes, and snippets.

@pavoldecky
Last active November 9, 2021 09:48
Show Gist options
  • Save pavoldecky/5c1b6cc64d4badfe0d2faca8b5391df4 to your computer and use it in GitHub Desktop.
Save pavoldecky/5c1b6cc64d4badfe0d2faca8b5391df4 to your computer and use it in GitHub Desktop.
Autoupdater.NET MVC Integration
[Route("updates/{xml?}")]
public IActionResult Updates(string xml)
{
string host = @"";
string username = "";
string password = @"";
string remoteDirectory = $"/updates/{xml}";
MemoryStream memoryStream = new System.IO.MemoryStream();
using (SftpClient sftp = new SftpClient(host, username, password))
{
try
{
sftp.Connect();
sftp.DownloadFile(remoteDirectory, memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
sftp.Disconnect();
}
catch (Exception e)
{
Console.WriteLine("An exception has been caught " + e.ToString());
}
}
string contentType = "application/xml";
string fileNameDisplayedToUser = xml;
return File(memoryStream, contentType, fileNameDisplayedToUser);
}
[Route("downloads/{zip?}")]
public IActionResult Downloads(string zip)
{
string host = @"";
string username = "";
string password = @"";
string remoteDirectory = $"/downloads/{zip}";
MemoryStream memoryStream = new System.IO.MemoryStream();
using (SftpClient sftp = new SftpClient(host, username, password))
{
try
{
sftp.Connect();
sftp.DownloadFile(remoteDirectory, memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
sftp.Disconnect();
}
catch (Exception e)
{
Console.WriteLine("An exception has been caught " + e.ToString());
}
}
string contentType = "application/zip";
string fileNameDisplayedToUser = zip;
return File(memoryStream, contentType, fileNameDisplayedToUser);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment