Last active
November 9, 2021 09:48
-
-
Save pavoldecky/5c1b6cc64d4badfe0d2faca8b5391df4 to your computer and use it in GitHub Desktop.
Autoupdater.NET MVC Integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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