public static bool IsDownloadTypeValid(Config.Modes mode, MCSyncFile.DownloadTypes downloadTypes) { if (downloadTypes == MCSyncFile.DownloadTypes.Client && mode == Config.Modes.Client) { return(true); } else if (downloadTypes == MCSyncFile.DownloadTypes.Server && mode == Config.Modes.Server) { return(true); } else if (downloadTypes == MCSyncFile.DownloadTypes.Common) { return(true); } return(false); }
private bool DownloadFile(MCSyncFile.FileTypes type, string directory, string file, MCSyncFile.DownloadTypes downloadTypes) { try { FtpWebRequest webRequest = (FtpWebRequest)WebRequest.Create("ftp://www.clussmanproductions.com/support/MCSyncNew/" + downloadTypes.ToString().ToLower() + "/" + type.ToString() + "/" + StripDirectory(file, type)); webRequest.Credentials = new NetworkCredential("Reporting", "NetLogon"); webRequest.Method = WebRequestMethods.Ftp.DownloadFile; FtpWebResponse response = (FtpWebResponse)webRequest.GetResponse(); if (!Directory.Exists(Path.GetDirectoryName(directory + "\\" + file))) { string path = Path.GetDirectoryName(directory + "\\" + file); Directory.CreateDirectory(path); } File.Delete(directory + "\\" + file); using (Stream responseStream = response.GetResponseStream()) using (Stream fileStream = File.OpenWrite(directory + "\\" + file)) { responseStream.CopyTo(fileStream); } return(true); } catch (Exception ex) { Task.Errors.Add(ex.Message); return(false); } }