diff --git a/AutoUpdater.NET/AutoUpdater.NET.csproj b/AutoUpdater.NET/AutoUpdater.NET.csproj
index 09d2c779..dde140cd 100644
--- a/AutoUpdater.NET/AutoUpdater.NET.csproj
+++ b/AutoUpdater.NET/AutoUpdater.NET.csproj
@@ -14,7 +14,7 @@
1.7.7.0
1.7.7.0
1.7.7.0
- true
+ False
AutoUpdater.NET.snk
en
Autoupdater.NET.Official
@@ -51,6 +51,11 @@
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
\ No newline at end of file
diff --git a/AutoUpdater.NET/AutoUpdater.cs b/AutoUpdater.NET/AutoUpdater.cs
index 00a7d927..1eff27dc 100644
--- a/AutoUpdater.NET/AutoUpdater.cs
+++ b/AutoUpdater.NET/AutoUpdater.cs
@@ -151,6 +151,12 @@ public static class AutoUpdater
///
public static bool ReportErrors = false;
+ ///
+ /// AutoUpdater.NET will not show the 'No Update Available' dialog if
+ /// no update is available and this is true.
+ ///
+ public static bool SilentOnNoUpdate = false;
+
///
/// Set this to false if your application doesn't need administrator privileges to replace the old version.
///
@@ -258,8 +264,8 @@ public static void Start(string appCast, Assembly myAssembly = null)
{
try
{
- ServicePointManager.SecurityProtocol |= (SecurityProtocolType) 192 |
- (SecurityProtocolType) 768 | (SecurityProtocolType) 3072;
+ ServicePointManager.SecurityProtocol |= (SecurityProtocolType)192 |
+ (SecurityProtocolType)768 | (SecurityProtocolType)3072;
}
catch (NotSupportedException)
{
@@ -331,9 +337,9 @@ public static void Start(string appCast, Assembly myAssembly = null)
return;
}
}
-
- Running = false;
}
+
+ Running = false;
};
backgroundWorker.RunWorkerAsync(assembly);
@@ -345,13 +351,13 @@ public static void Start(string appCast, Assembly myAssembly = null)
private static object CheckUpdate(Assembly mainAssembly)
{
var companyAttribute =
- (AssemblyCompanyAttribute) GetAttribute(mainAssembly, typeof(AssemblyCompanyAttribute));
+ (AssemblyCompanyAttribute)GetAttribute(mainAssembly, typeof(AssemblyCompanyAttribute));
string appCompany = companyAttribute != null ? companyAttribute.Company : "";
if (string.IsNullOrEmpty(AppTitle))
{
var titleAttribute =
- (AssemblyTitleAttribute) GetAttribute(mainAssembly, typeof(AssemblyTitleAttribute));
+ (AssemblyTitleAttribute)GetAttribute(mainAssembly, typeof(AssemblyTitleAttribute));
AppTitle = titleAttribute != null ? titleAttribute.Title : mainAssembly.GetName().Name;
}
@@ -362,24 +368,32 @@ private static object CheckUpdate(Assembly mainAssembly)
PersistenceProvider ??= new RegistryPersistenceProvider(registryLocation);
BaseUri = new Uri(AppCastURL);
+ string xml = string.Empty;
+
+ switch (BaseUri.Scheme.ToLower())
+ {
+ case "sftp":
+ xml = GetUpdateXmlBySSHClient();
+ break;
+
+ default:
+ xml = GetUpdateXmlByWebClient();
+ break;
+ }
UpdateInfoEventArgs args;
- using (MyWebClient client = GetWebClient(BaseUri, BasicAuthXML))
+
+ if (ParseUpdateInfoEvent == null)
{
- string xml = client.DownloadString(BaseUri);
-
- if (ParseUpdateInfoEvent == null)
- {
- XmlSerializer xmlSerializer = new XmlSerializer(typeof(UpdateInfoEventArgs));
- XmlTextReader xmlTextReader = new XmlTextReader(new StringReader(xml)) {XmlResolver = null};
- args = (UpdateInfoEventArgs) xmlSerializer.Deserialize(xmlTextReader);
- }
- else
- {
- ParseUpdateInfoEventArgs parseArgs = new ParseUpdateInfoEventArgs(xml);
- ParseUpdateInfoEvent(parseArgs);
- args = parseArgs.UpdateInfo;
- }
+ XmlSerializer xmlSerializer = new XmlSerializer(typeof(UpdateInfoEventArgs));
+ XmlTextReader xmlTextReader = new XmlTextReader(new StringReader(xml)) { XmlResolver = null };
+ args = (UpdateInfoEventArgs)xmlSerializer.Deserialize(xmlTextReader);
+ }
+ else
+ {
+ ParseUpdateInfoEventArgs parseArgs = new ParseUpdateInfoEventArgs(xml);
+ ParseUpdateInfoEvent(parseArgs);
+ args = parseArgs.UpdateInfo;
}
if (string.IsNullOrEmpty(args?.CurrentVersion) || string.IsNullOrEmpty(args.DownloadURL))
@@ -387,7 +401,7 @@ private static object CheckUpdate(Assembly mainAssembly)
throw new MissingFieldException();
}
- args.InstalledVersion = InstalledVersion ?? mainAssembly.GetName().Version;
+ args.InstalledVersion = InstalledVersion != null ? InstalledVersion : mainAssembly.GetName().Version;
args.IsUpdateAvailable = new Version(args.CurrentVersion) > args.InstalledVersion;
if (!Mandatory)
@@ -434,10 +448,34 @@ private static object CheckUpdate(Assembly mainAssembly)
}
}
}
-
return args;
}
+ private static string GetUpdateXmlBySSHClient()
+ {
+ string xml = string.Empty;
+ string host = BaseUri.Host;
+
+ MySSHClient client = new MySSHClient(
+ host: host, userName: FtpCredentials.UserName,
+ password: FtpCredentials.Password);
+
+ xml = client.GetFileContentAsString(BaseUri.AbsolutePath);
+
+ return xml;
+ }
+
+ private static string GetUpdateXmlByWebClient()
+ {
+ string xml = string.Empty;
+
+ using (MyWebClient client = GetWebClient(BaseUri, BasicAuthXML))
+ {
+ xml = client.DownloadString(BaseUri);
+ }
+
+ return xml;
+ }
private static bool StartUpdate(object result)
{
if (result is DateTime time)
@@ -481,7 +519,7 @@ private static bool StartUpdate(object result)
return true;
}
- if (ReportErrors)
+ if (ReportErrors && !SilentOnNoUpdate)
{
MessageBox.Show(Resources.UpdateUnavailableMessage,
Resources.UpdateUnavailableCaption,
@@ -498,7 +536,7 @@ private static void ShowError(Exception exception)
{
if (CheckForUpdateEvent != null)
{
- CheckForUpdateEvent(new UpdateInfoEventArgs {Error = exception});
+ CheckForUpdateEvent(new UpdateInfoEventArgs { Error = exception });
}
else
{
@@ -518,8 +556,6 @@ private static void ShowError(Exception exception)
}
}
}
-
- Running = false;
}
///
@@ -547,7 +583,7 @@ internal static void Exit()
{
if (process.CloseMainWindow())
{
- process.WaitForExit((int) TimeSpan.FromSeconds(10)
+ process.WaitForExit((int)TimeSpan.FromSeconds(10)
.TotalMilliseconds); //give some time to process message
}
@@ -589,7 +625,7 @@ private static Attribute GetAttribute(Assembly assembly, Type attributeType)
return null;
}
- return (Attribute) attributes[0];
+ return (Attribute)attributes[0];
}
internal static string GetUserAgent()
@@ -695,5 +731,15 @@ internal static MyWebClient GetWebClient(Uri uri, IAuthentication basicAuthentic
return webClient;
}
+
+ internal static MySSHClient GetSSHClient(Uri uri, IAuthentication basicAuthentication)
+ {
+ MySSHClient sshClient = new MySSHClient(
+ host: uri.Host,
+ userName: FtpCredentials.UserName,
+ password: FtpCredentials.Password);
+
+ return sshClient;
+ }
}
}
\ No newline at end of file
diff --git a/AutoUpdater.NET/DownloadProgressChangedEventArgs.cs b/AutoUpdater.NET/DownloadProgressChangedEventArgs.cs
new file mode 100644
index 00000000..6e2d7ce9
--- /dev/null
+++ b/AutoUpdater.NET/DownloadProgressChangedEventArgs.cs
@@ -0,0 +1,34 @@
+using System.ComponentModel;
+
+namespace AutoUpdaterDotNET
+{
+ //
+ // Summary:
+ // Provides data for the SSH client DownloadProgressChanged event.
+ public class DownloadProgressChangedEventArgs : ProgressChangedEventArgs
+ {
+ public DownloadProgressChangedEventArgs(long bytesReceived, long totalBytesToReceive,
+ int progressPercentage, object userState)
+ : base(progressPercentage, userState)
+ {
+ BytesReceived = bytesReceived;
+ TotalBytesToReceive = totalBytesToReceive;
+ }
+
+
+ //
+ // Summary:
+ // Gets the number of bytes received.
+ //
+ // Returns:
+ // An System.Int64 value that indicates the number of bytes received.
+ public long BytesReceived { get; }
+ //
+ // Summary:
+ // Gets the total number of bytes in a System.Net.WebClient data download operation.
+ //
+ // Returns:
+ // An System.Int64 value that indicates the number of bytes that will be received.
+ public long TotalBytesToReceive { get; }
+ }
+}
diff --git a/AutoUpdater.NET/FileDownloadClient.cs b/AutoUpdater.NET/FileDownloadClient.cs
new file mode 100644
index 00000000..3f1a62b2
--- /dev/null
+++ b/AutoUpdater.NET/FileDownloadClient.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace AutoUpdaterDotNET
+{
+ public abstract class FileDownloadClient : IFileDownloadClient
+ {
+ ///
+ /// The required constructor for the class.
+ ///
+ ///
+ public FileDownloadClient(FileDownloadClientType type)
+ {
+ this.Type = type;
+ }
+
+
+ public virtual FileDownloadClientType Type { get; private set; }
+
+
+ }
+}
diff --git a/AutoUpdater.NET/FileDownloadClientType.cs b/AutoUpdater.NET/FileDownloadClientType.cs
new file mode 100644
index 00000000..b5e09b11
--- /dev/null
+++ b/AutoUpdater.NET/FileDownloadClientType.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace AutoUpdaterDotNET
+{
+ ///
+ /// Identifies the type of download client required to retrieve the
+ /// update file, i.e. WebClient, SFTP, etc.
+ ///
+ public enum FileDownloadClientType
+ {
+ ///
+ /// The type of client to use is unknown.
+ ///
+ Unspecified = 0,
+
+ ///
+ /// The update process will use the Web Client for
+ /// a traditional HTTP(S) file download.
+ ///
+ WebClient = 1,
+
+ ///
+ /// The update process will use an SSH client to connect
+ /// to a secure FTP site that is hosting the update file.
+ ///
+ SFTPClient = 2
+ }
+}
diff --git a/AutoUpdater.NET/IFileDownloadClient.cs b/AutoUpdater.NET/IFileDownloadClient.cs
new file mode 100644
index 00000000..2f0c72f7
--- /dev/null
+++ b/AutoUpdater.NET/IFileDownloadClient.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace AutoUpdaterDotNET
+{
+ public interface IFileDownloadClient
+ {
+ FileDownloadClientType Type { get; }
+
+
+ }
+}
diff --git a/AutoUpdater.NET/MySSHClient.cs b/AutoUpdater.NET/MySSHClient.cs
new file mode 100644
index 00000000..52684731
--- /dev/null
+++ b/AutoUpdater.NET/MySSHClient.cs
@@ -0,0 +1,130 @@
+using Renci.SshNet;
+using Renci.SshNet.Sftp;
+using System;
+using System.ComponentModel;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AutoUpdaterDotNET
+{
+ public class MySSHClient
+ {
+ private string _Host;
+ private int _Port;
+ private string _UserName;
+ private string _Password;
+
+ public Action
private void InitializeComponent()
{
- this.buttonCheckForUpdate = new System.Windows.Forms.Button();
+ this.buttonCheckForUpdateViaHttp = new System.Windows.Forms.Button();
this.labelVersion = new System.Windows.Forms.Label();
+ this.buttonCheckForUpdateViaSftp = new System.Windows.Forms.Button();
this.SuspendLayout();
//
- // buttonCheckForUpdate
+ // buttonCheckForUpdateViaHttp
//
- this.buttonCheckForUpdate.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
+ this.buttonCheckForUpdateViaHttp.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
- this.buttonCheckForUpdate.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.buttonCheckForUpdate.Location = new System.Drawing.Point(12, 54);
- this.buttonCheckForUpdate.Name = "buttonCheckForUpdate";
- this.buttonCheckForUpdate.Size = new System.Drawing.Size(196, 40);
- this.buttonCheckForUpdate.TabIndex = 0;
- this.buttonCheckForUpdate.Text = "Check for update";
- this.buttonCheckForUpdate.UseVisualStyleBackColor = true;
- this.buttonCheckForUpdate.Click += new System.EventHandler(this.ButtonCheckForUpdate_Click);
+ this.buttonCheckForUpdateViaHttp.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.buttonCheckForUpdateViaHttp.Location = new System.Drawing.Point(12, 54);
+ this.buttonCheckForUpdateViaHttp.Name = "buttonCheckForUpdateViaHttp";
+ this.buttonCheckForUpdateViaHttp.Size = new System.Drawing.Size(161, 40);
+ this.buttonCheckForUpdateViaHttp.TabIndex = 0;
+ this.buttonCheckForUpdateViaHttp.Text = "Check for update via HTTP";
+ this.buttonCheckForUpdateViaHttp.UseVisualStyleBackColor = true;
+ this.buttonCheckForUpdateViaHttp.Click += new System.EventHandler(this.ButtonCheckForUpdateViaHttp_Click);
//
// labelVersion
//
@@ -55,13 +56,27 @@ private void InitializeComponent()
this.labelVersion.TabIndex = 1;
this.labelVersion.Text = "Current version : 1.0.0.0";
//
+ // buttonCheckForUpdateViaSftp
+ //
+ this.buttonCheckForUpdateViaSftp.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonCheckForUpdateViaSftp.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.buttonCheckForUpdateViaSftp.Location = new System.Drawing.Point(203, 54);
+ this.buttonCheckForUpdateViaSftp.Name = "buttonCheckForUpdateViaSftp";
+ this.buttonCheckForUpdateViaSftp.Size = new System.Drawing.Size(161, 40);
+ this.buttonCheckForUpdateViaSftp.TabIndex = 2;
+ this.buttonCheckForUpdateViaSftp.Text = "Check for update via SFTP";
+ this.buttonCheckForUpdateViaSftp.UseVisualStyleBackColor = true;
+ this.buttonCheckForUpdateViaSftp.Click += new System.EventHandler(this.buttonCheckForUpdateViaSftp_Click);
+ //
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(220, 106);
+ this.ClientSize = new System.Drawing.Size(376, 106);
+ this.Controls.Add(this.buttonCheckForUpdateViaSftp);
this.Controls.Add(this.labelVersion);
- this.Controls.Add(this.buttonCheckForUpdate);
+ this.Controls.Add(this.buttonCheckForUpdateViaHttp);
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
@@ -77,7 +92,8 @@ private void InitializeComponent()
#endregion
- private System.Windows.Forms.Button buttonCheckForUpdate;
+ private System.Windows.Forms.Button buttonCheckForUpdateViaHttp;
private System.Windows.Forms.Label labelVersion;
+ private System.Windows.Forms.Button buttonCheckForUpdateViaSftp;
}
}
\ No newline at end of file
diff --git a/AutoUpdaterTest/FormMain.cs b/AutoUpdaterTest/FormMain.cs
index 13969a73..2807aedb 100644
--- a/AutoUpdaterTest/FormMain.cs
+++ b/AutoUpdaterTest/FormMain.cs
@@ -233,7 +233,7 @@ private void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args)
}
}
- private void ButtonCheckForUpdate_Click(object sender, EventArgs e)
+ private void ButtonCheckForUpdateViaHttp_Click(object sender, EventArgs e)
{
//Uncomment below lines to select download path where update is saved.
@@ -248,5 +248,29 @@ private void ButtonCheckForUpdate_Click(object sender, EventArgs e)
AutoUpdater.ClearAppDirectory = false;
AutoUpdater.Start("https://rbsoft.org/updates/AutoUpdaterTest.xml");
}
+
+ private void buttonCheckForUpdateViaSftp_Click(object sender, EventArgs e)
+ {
+ //Uncomment below lines to select download path where update is saved.
+
+ //FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
+ //if (folderBrowserDialog.ShowDialog().Equals(DialogResult.OK))
+ //{
+ // AutoUpdater.DownloadPath = folderBrowserDialog.SelectedPath;
+ // AutoUpdater.Mandatory = true;
+ // AutoUpdater.Start("https://rbsoft.org/updates/AutoUpdaterTest.xml");
+ //}
+
+ AutoUpdater.Mandatory = true;
+ //AutoUpdater.Start("https://rbsoft.org/updates/AutoUpdaterTest.xml");
+
+ // SFTP test
+ AutoUpdater.Synchronous = false;
+ AutoUpdater.Start(
+ appCast: "sftp://files.mydomain.com/AutoUpdaterTest.xml",
+ ftpCredentials: new NetworkCredential(
+ userName: "some-username",
+ password: "VRF1peB9f^2V6%LCMTToFc"));
+ }
}
}
\ No newline at end of file
diff --git a/AutoUpdaterTest/packages.config b/AutoUpdaterTest/packages.config
index ea29129e..f98a5581 100644
--- a/AutoUpdaterTest/packages.config
+++ b/AutoUpdaterTest/packages.config
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/README.md b/README.md
index bcf9aa22..af209bcc 100644
--- a/README.md
+++ b/README.md
@@ -115,6 +115,14 @@ AutoUpdater.Start("ftp://rbsoft.org/updates/AutoUpdaterTest.xml", new NetworkCre
If you are using FTP download URL in the XML file then credentials provided here will be used to authenticate the request.
+### Download Update file and XML using SFTP (FTP over SSH)
+
+Using an SFTP server for your XML file is also supported. Simply provide the URL to your SFTP server along with the credentials required to access it securely as shown below.
+
+````csharp
+AutoUpdater.Start("sftp://securefiles.rbsoft.org/updates/AutoUpdaterTest.xml", new NetworkCredential("SftpUserName", "SftpPassword"));
+````
+
### Check for updates synchronously
If you want to check for updates synchronously then set Synchronous to true before starting the update as shown below.
diff --git a/ZipExtractor/ZipExtractor.csproj b/ZipExtractor/ZipExtractor.csproj
index 09df56fe..9b6ebfa3 100644
--- a/ZipExtractor/ZipExtractor.csproj
+++ b/ZipExtractor/ZipExtractor.csproj
@@ -15,7 +15,7 @@
1.3.2.0
ZipExtractor.ico
app.manifest
- true
+ False
ZipExtractor.snk
en
default
@@ -44,6 +44,12 @@
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
True