Auto updater added
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
|
||||
|
||||
namespace PWAppUpdater.FTP
|
||||
{
|
||||
class FTPManager
|
||||
{
|
||||
private string BaseUri;
|
||||
private NetworkCredential credential;
|
||||
|
||||
public FTPManager(string baseUri, string username, string password)
|
||||
{
|
||||
BaseUri = baseUri;
|
||||
credential = new NetworkCredential(username, password);
|
||||
}
|
||||
|
||||
public void DownloadFile(string FTPPath, string localPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(BaseUri + FTPPath);
|
||||
request.Method = WebRequestMethods.Ftp.DownloadFile;
|
||||
request.Credentials = credential;
|
||||
request.KeepAlive = false;
|
||||
request.UseBinary = true;
|
||||
request.UsePassive = true;
|
||||
|
||||
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
|
||||
Stream responseStream = response.GetResponseStream();
|
||||
|
||||
using (Stream s = File.Create(localPath))
|
||||
{
|
||||
responseStream.CopyTo(s);
|
||||
}
|
||||
response.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user