public FtpSync() { CreateNotifyIcon(); projectsList = new List<Project>(); LoadProjects(); foreach(Project project in projectsList) { if (Validate(project)) { FTPConnection ftpConn = new FTPConnection(project.LocalPath, project.RemoteHostname, project.RemotePath, project.RemoteUsername, project.RemotePassword); CreateFileSystemWatcher(project, ftpConn); } } }
private void watcher_Changed(object sender, FileSystemEventArgs e, Project project, FTPConnection ftpConn) { try { ftpConn.Upload(e.FullPath); ShowNotifyBalloonTip(ToolTipIcon.Info, Path.GetFileName(e.FullPath) + " uploaded."); } catch (Exception) { ShowNotifyBalloonTip(ToolTipIcon.Error, "Could not upload " + Path.GetFileName(e.FullPath)); } }
private void CreateFileSystemWatcher(Project project, FTPConnection ftpConn) { watcher = new FileSystemWatcher(); watcher.Path = project.LocalPath; watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; //watcher.Filter = "*.txt"; Filter maken voor files die je NIET moet checken :)) watcher.Changed += new FileSystemEventHandler((sender, e) => watcher_Changed(sender, e, project, ftpConn)); watcher.Created += new FileSystemEventHandler((sender, e) => watcher_Changed(sender, e, project, ftpConn)); //watcher.Deleted += new FileSystemEventHandler((sender, e) => watcher_Changed(sender, e, project, ftpConn)); //watcher.Renamed += new RenamedEventHandler((sender, e) => watcher_Changed(sender, e, project, ftpConn)); watcher.EnableRaisingEvents = true; }