/// <summary> /// Uploads all files within the specified directory. /// </summary> /// <param name="directoryPath">All files within this directory will be uploaded to the FTP server.</param> public void UploadLogs(string directoryPath) { if (_isVerbose) Console.WriteLine("*** UPLOADING DAILY LOG FILES ({0}) ***", DateTime.Now); FTPclient ftp = new FTPclient(_ftpHost, _ftpUser, _ftpPass); //string individualLogDirecotry = Path.Combine(LogDirectory, "individual"); foreach (string logFile in Directory.GetFiles(directoryPath)) { if (_isVerbose) Console.Write(" - Uploading {0}... ", logFile); if (ftp.Upload(Path.GetFullPath(logFile), String.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}-{1}", DateTime.Now, Path.GetFileName(logFile)))) { File.Delete(logFile); if (_isVerbose) Console.WriteLine("done!"); } } if (_isVerbose) Console.WriteLine("*** UPLOAD COMPLETE ***"); }
/// <summary> /// Uploading a File to FTP Server /// </summary> /// <param name="UploadFilePath">Path of the File on Local File System. ex: c:\Users\FileName.txt</param> /// <param name="UploadDirectory">Upload Directory on the Remote FTP Server</param> /// <param name="FtpClient">FTP Client We will be using</param> public frmUpload(string UploadFilePath, string UploadDirectory, FTPclient Ftpclient) { InitializeComponent(); //Setup Variables FileName = System.IO.Path.GetFileName(UploadFilePath); //FileName without Directory. ex: FileName.txt lblFileName.Text = Ftpclient.Hostname + UploadDirectory + FileName; //lblFileName displays full Upload Path. lblUploadDirectory.Text = UploadDirectory; //Upload Directory FtpClient = Ftpclient; //Aero Composition Event AeroGlassCompositionChanged += new AeroGlassCompositionChangedEvent(frmUpload_AeroGlassCompositionChanged); if (AeroGlassCompositionEnabled) { //We don't want pnlNonTransparent and the controls in it to be part of AERO //but we do want Aero...looks cool ;) ExcludeControlFromAeroGlass(pnlNonTransparent); } else { this.BackColor = Color.Teal; } //Show Form this.Show(); //Setup our Download Client and Start Downloading FtpClient.CurrentDirectory = UploadDirectory; FtpClient.OnUploadCompleted += new FTPclient.UploadCompletedHandler(FtpClient_OnUploadCompleted); FtpClient.OnUploadProgressChanged += new FTPclient.UploadProgressChangedHandler(FtpClient_OnUploadProgressChanged); FtpClient.Upload(UploadFilePath, UploadDirectory + FileName); }
/// <summary> /// Uploads the specified file to the FTP server. /// </summary> /// <param name="localFilename">The filename of the log file you wish to upload.</param> /// <param name="remoteFilename">The filename that you wish to save the log file with on the FTP server.</param> public void UploadLog(string localFilename, string remoteFilename) { while (true) { if (!File.Exists(localFilename)) return; if (_isVerbose) Console.WriteLine("*** UPLOADING OVERALL LOG FILE ***"); FTPclient ftp = new FTPclient(_ftpHost, _ftpUser, _ftpPass); //if (ftp.Upload(Path.GetFullPath(OverallLog), String.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}.log", DateTime.Now))) if (ftp.Upload(Path.GetFullPath(localFilename), String.Format("{0}.log", remoteFilename))) { if (_isVerbose) Console.WriteLine("*** UPLOAD SUCCESSFUL ***"); } else { if (_isVerbose) Console.WriteLine("*** UPLOAD FAILED - RETRYING ***"); continue; } break; } }
void tFtp_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { ConfigHandler conf = ConfigHandler.instance; FTPclient ftp = new FTPclient(conf.ftpHost, conf.ftpUserName, conf.ftpUserPassword); DirectoryInfo di = new DirectoryInfo(ConfigHandler.instance.tempfolder); foreach (FileInfo f in di.GetFiles()) { if (f.Length > ConfigHandler.instance.maximmiumValue) { string fileName = String.Concat(ftp.CurrentDirectory, "/", f.Name); bool res = ftp.Upload(f, fileName); if (res) { f.Delete(); } } } string stmtFullPath = String.Concat(ftp.CurrentDirectory, conf.stmtFile); if (ftp.FtpFileExists(stmtFullPath)) { string downPath = Path.Combine(conf.tempfolder, conf.stmtFile); ftp.Download(stmtFullPath, downPath, true); ftp.FtpDelete(stmtFullPath); //Bussiness Method ProcessStmtFile(downPath); } }
public bool Download(Uri host, string fileName, string localFilename, bool permitOverwrite) { FTPclient ftp = new FTPclient(host.AbsoluteUri, FtpUser, FtpPassword); ftp.UsePassive = true; return(ftp.Download(fileName, localFilename, permitOverwrite)); }
public FTPdirectory GetFtpFiles(Uri Host, string ext = "") { FTPclient ftp = new FTPclient(Host.AbsoluteUri, FtpUser, FtpPassword); ftp.UsePassive = true; FTPdirectory ftpDir = ftp.ListDirectoryDetail(); return(ftpDir.GetFiles("")); }
public bool Upload(Uri host, string localFilename) { string targFileName = Path.GetFileName(localFilename); FTPclient ftp = new FTPclient(host.AbsoluteUri, FtpUser, FtpPassword); ftp.UsePassive = true; return(ftp.Upload(localFilename, targFileName)); }
private IFTPClient getFTPClient(SiteManifest manifest, string password) { var client = new FTPclient(manifest.FTPServer, manifest.DefaultUserName, password, true); string path = manifest.FTPPath; if (!path.StartsWith("/")) { path = "/" + path; } client.CurrentDirectory = path; FTPClientValidationDecorator d = new FTPClientValidationDecorator(client); return(d); }
private void CauHinh() { try { LoadDataSysConfigRadio(); FtpClient = new FTPclient(PropertyLib._FTPProperties.IPAddress, PropertyLib._FTPProperties.UID, PropertyLib._FTPProperties.PWD); _FtpClientCurrentDirectory = FtpClient.CurrentDirectory; _baseDirectory = Utility.DoTrim(PropertyLib._FTPProperties.ImageFolder); if (_baseDirectory.EndsWith(@"\")) _baseDirectory = _baseDirectory.Substring(0, _baseDirectory.Length - 1); if (!Directory.Exists(_baseDirectory)) { Directory.CreateDirectory(_baseDirectory); } } catch { } }
private static bool forPublic = false; // 是否开始public版功能 private void Form1_Load(object sender, EventArgs e) { strXMLFile = Application.StartupPath + "\\local.xml"; AppStartPath = Application.StartupPath + "\\"; // 初始化ftp ftp = new FTPclient(hostName, user, psw); //RunExternCmd(); if (updating = IsUpdate()) { Thread thread = new Thread(new ThreadStart(progress)); thread.Start(); } else { Application.Exit(); } }
private void CauHinh() { try { LoadDataSysConfigRadio(); FtpClient = new FTPclient(PropertyLib._FTPProperties.IPAddress, PropertyLib._FTPProperties.UID, PropertyLib._FTPProperties.PWD); _FtpClientCurrentDirectory = FtpClient.CurrentDirectory; _baseDirectory = Utility.DoTrim(PropertyLib._FTPProperties.ImageFolder); if (_baseDirectory.EndsWith(@"\")) { _baseDirectory = _baseDirectory.Substring(0, _baseDirectory.Length - 1); } if (!Directory.Exists(_baseDirectory)) { Directory.CreateDirectory(_baseDirectory); } } catch { } }
private void btnLogIn_Click(object sender, EventArgs e) { try { //Set FTP FTPclient objFtp = new FTPclient(txtHostName.Text, txtUserName.Text, txtPassword.Text); objFtp.CurrentDirectory = "/"; Main = new frmMain(); //Set FTP Client in MAIN form Main.SetFtpClient(objFtp); //Show MAIN form and HIDE this one Main.Show(); this.Hide(); } catch (Exception ex) { //Display Error MessageBox.Show(ex.Message); } }
/// <summary> /// Sets up the FTPClient for this Form. Called from frmLogin. /// </summary> /// <param name="client">FTPclient on frmLogin is used to refrence the FtpClient here.</param> public void SetFtpClient(Win7FTP.Library.FTPclient client) { //Set FtpClient FtpClient = client; //Display the Welcome Message Message = new ListViewItem(); Message.Text = DateTime.Now.ToLongTimeString() + " " + DateTime.Now.ToLongDateString(); Message.SubItems.Add("Welcome Message"); Message.SubItems.Add(FtpClient.WelcomeMessage); Message.SubItems.Add("No Code"); Message.SubItems.Add("/"); lstMessages.Items.Add(Message); //Setup OnMessageReceived Event FtpClient.OnNewMessageReceived += new FTPclient.NewMessageHandler(FtpClient_OnNewMessageReceived); //Open and Display Root Directory and Files/Folders in it foreach (FTPfileInfo folder in FtpClient.ListDirectoryDetail("/")) { ListViewItem item = new ListViewItem(); item.Text = folder.Filename; if (folder.FileType == FTPfileInfo.DirectoryEntryTypes.Directory) { item.SubItems.Add("Folder"); } else { item.SubItems.Add("File"); } item.SubItems.Add(folder.FullName); item.SubItems.Add(folder.Permission); item.SubItems.Add(folder.FileDateTime.ToShortDateString() + " " + folder.FileDateTime.ToShortTimeString()); item.SubItems.Add(GetFileSize(folder.Size)); lstRemoteSiteFiles.Items.Add(item); } }
/// <summary> /// frmDownload constructor /// </summary> /// <param name="Filename">Name of the File to Download</param> /// <param name="Current_Directory">Current Directory of the FTPClient; where file will be downloaded from.</param> /// <param name="SavePath">Path where the File will be saved.</param> /// <param name="Ftpclient">FTPClient from frmMain that will be refrenced here to FtpClient variable.</param> public frmDownload(string Filename, string Current_Directory, string SavePath, FTPclient Ftpclient) { //Init Form InitializeComponent(); //Setup Variables FileName = Filename; SaveFilePath = SavePath; CurrentDirectory = Current_Directory; lblDownloadFrom.Text = Ftpclient.Hostname + Current_Directory + FileName; //ex: ftp://ftp.somesite.com/current_dir/File.exe lblSavePath.Text = SaveFilePath; FtpClient = Ftpclient; TaskBarManager.ClearProgressValue(); //Aero Composition Event AeroGlassCompositionChanged += new AeroGlassCompositionChangedEvent(Form1_AeroGlassCompositionChanged); if (AeroGlassCompositionEnabled) { //We don't want pnlNonTransparent and the controls in it to be part of AERO //but we do want Aero...looks cool ;) ExcludeControlFromAeroGlass(pnlNonTransparent); } else { this.BackColor = Color.Teal; } //Show Form this.Show(); //Setup our Download Client and Start Downloading FtpClient.CurrentDirectory = Current_Directory; FtpClient.OnDownloadProgressChanged += new FTPclient.DownloadProgressChangedHandler(FtpClient_OnDownloadProgressChanged); FtpClient.OnDownloadCompleted += new FTPclient.DownloadCompletedHandler(FtpClient_OnDownloadCompleted); FtpClient.Download(FileName, SavePath, true); }
private void CauHinh() { try { chkPreview.Checked = PropertyLib._FTPProperties.PrintPreview; chkInsaukhiluu.Checked = PropertyLib._FTPProperties.PrintAfterSave; cmdGetImages.Enabled = PropertyLib._FTPProperties.Push2FTP; cmdDelFTPImages.Enabled = PropertyLib._FTPProperties.Push2FTP; FtpClient = new FTPclient(PropertyLib._FTPProperties.IPAddress, PropertyLib._FTPProperties.UID, PropertyLib._FTPProperties.PWD); _FtpClientCurrentDirectory = FtpClient.CurrentDirectory; _baseDirectory = Utility.DoTrim(PropertyLib._FTPProperties.ImageFolder); if (_baseDirectory.EndsWith(@"\")) _baseDirectory = _baseDirectory.Substring(0, _baseDirectory.Length - 1); if (!Directory.Exists(_baseDirectory)) { Directory.CreateDirectory(_baseDirectory); } } catch { } }
private void button49_Click(object sender, EventArgs e) { try { string str = "Connexion : Ok"; bool flag = false; FTPclient fTPclient = new FTPclient() { Retry = 0 }; try { fTPclient.Hostname = this.tFTPServ.Text; fTPclient.Username = this.tFTPLog.Text; fTPclient.Password = this.tFTPPass.Text; fTPclient.UseSSL = this.cFTPSSL.Checked; fTPclient.CurrentDirectory = this.tFTPRacine.Text; fTPclient.ListDirectory(""); } catch (Exception exception1) { ProjectData.SetProjectError(exception1); Exception exception = exception1; Interaction.MsgBox(string.Concat("Erreur lors de la connexion au serveur FTP, vérifier que vous avez accès au serveur FTP via un client FTP (FileZilla, InternetExplorer, ...)\r\n", exception.Message), MsgBoxStyle.Critical, null); ProjectData.ClearProjectError(); return; } try { fTPclient.ListDirectory(""); str = string.Concat(str, "\r\nListe des fichiers : OK"); } catch (Exception exception2) { ProjectData.SetProjectError(exception2); str = string.Concat(str, "\r\nErreur lors de la liste des fichiers : ", exception2.Message); flag = true; ProjectData.ClearProjectError(); } try { fTPclient.FtpCreateDirectory("MG2S_FTP_CLIENT_TEST"); str = string.Concat(str, "\r\nCreation de répertoire : OK"); } catch (Exception exception3) { ProjectData.SetProjectError(exception3); str = string.Concat(str, "\r\nErreur lors de la creation de répertoire : ", exception3.Message); flag = true; ProjectData.ClearProjectError(); } try { fTPclient.FtpDeleteDirectory("MG2S_FTP_CLIENT_TEST"); str = string.Concat(str, "\r\nSuppression de répertoire : OK"); } catch (Exception exception4) { ProjectData.SetProjectError(exception4); str = string.Concat(str, "\r\nErreur lors de la suppression de répertoire : ", exception4.Message); flag = true; ProjectData.ClearProjectError(); } if (!flag) { Interaction.MsgBox("Connexion et tests de transfert réussi.", MsgBoxStyle.Information, this.Text); } else { Interaction.MsgBox(str, MsgBoxStyle.Exclamation, this.Text); } } catch (Exception exception6) { ProjectData.SetProjectError(exception6); Exception exception5 = exception6; Interaction.MsgBox(exception5.Message, MsgBoxStyle.Critical, this.Text); ProjectData.ClearProjectError(); } }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (ConfigurationManager.AppSettings["remoting"] == "true") { EnableRemoting = true; } if (args.Length < 1) { MessageBox.Show(string.Format("启动失败,请使用 UpdatePrograme.exe 启动本程序。"), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } #if (!_DEBUG) if (ProgramAlreadyRunning() && args[0] != "-Debug") { MessageBox.Show("此工具不能双开。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } #endif //add by cuiwei 07.8.21 EV ev = new EV(); ev.evPath(Path.GetDirectoryName(Application.ExecutablePath)); //add end // ftp init m_ftp = new FTPclient(m_ftp_hostName, m_ftp_user, m_ftp_psw); //m_ftp.Upload("c:/path.txt", m_ftp_basedir + "xxxx"); // 数据库选择 if (!m_bSkillBranch) { if (forPublic) { m_bLoadBackupDB = false; } else { //DialogResult dr = MessageBox.Show("要读Head策划库,点<是>;\r\n要读分支库(1-0-8-1380,2009.03.25),点<否>。", "选择策划库", MessageBoxButtons.YesNo, MessageBoxIcon.Question); //if (dr == DialogResult.Yes) // m_bLoadBackupDB = false; //else // m_bLoadBackupDB = true; DialogResult dr = MessageBox.Show("要读Head策划库,点<是>;\r\n要退出程序,点<否>。", "是否继续", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) m_bLoadBackupDB = false; else return; } } TimeLog log = null; do { try { if (!InitSettings()) return; if (m_bRestart) { m_bRestart = false; } m_MainForm = new MainForm(); try { log = new TimeLog(); ClearRecordLocks(MainForm.conn); } catch (Exception ex) { MessageBox.Show(ex.Message); } if (RightsSettings.AllowSave) log.Log(TimeLog.enumLogType.ltstart, "主窗口", "应用程序启动", "主版本=" + Helper.GetVersionInfo()); else log.Log(TimeLog.enumLogType.ltstart, "主窗口", "应用程序启动", "主版本=" + Helper.GetVersionInfo() + " [只读版本]"); m_MainForm.Text += "(" + Helper.GetVersionInfo() + ")"; Application.Run(m_MainForm); m_rightmgr.Uninit(); } catch (Exception ex) { MessageBox.Show(string.Format("{0}", ex.Message), "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } finally { if (log != null) { log.Log(TimeLog.enumLogType.ltend, null, null, null); log.Clear(); } } } while(m_bRestart); // 检查是否需要重新启动主窗口 if (EnableRemoting) { DataTableServerProxy.DisconnectServer(); } }