/// <summary> /// File via FTP öffnen /// </summary> /// <returns></returns> private void logViaFTPÖffnenToolStripMenuItem_Click(object sender, EventArgs e) { TextBox.Clear(); IniFile lIni = new IniFile(); if (lIni.Read("LOG", "Receiver") == "") { return; } string ftpUri = lIni.Read("IP", "Receiver"); string ftpUser = lIni.Read("USER", "Receiver");; string passwd = lIni.Read("PWD", "Receiver"); string ftpfileName = Path.GetFileName(lIni.Read("LOG", "Receiver")); string ftpfilePath = lIni.Read("LOG", "Receiver"); ftpfilePath = ftpfilePath.Remove(Math.Max(0, ftpfilePath.Length - ftpfileName.Length - 1), ftpfileName.Length + 1); FTPConnection ftpCon = new FTPConnection(); string localFileName = Path.GetTempFileName(); //Prgressbar aufbauen ProgressForm lProgress = new ProgressForm(); lProgress.StartPosition = FormStartPosition.CenterParent; lProgress.Show(this); lProgress.SetProgress("Öffne FTP Verbindung", 0); //FTP verbinden ftpCon.Open(ftpUri, ftpUser, passwd, FTPMode.Passive); lProgress.SetProgress("Wechsle Verzeichnis", 20); ftpCon.SetCurrentDirectory(ftpfilePath); lProgress.SetProgress("Lade Daten", 40); ftpCon.GetFile(ftpfileName, localFileName, FTPFileTransferType.Binary); lProgress.SetProgress("Schließe Verbindung", 60); ftpCon.Close(); lProgress.SetProgress("Lese Datei", 80); readFile(localFileName); //Ende lProgress.SetProgress("Fertig ...", 100); lProgress.Close(); CountLines(); DetectCamType(); ReadLengthInfo(vCamType); }
public bool Process(Queue.QueueItem item) { string ftpHost = Settings.Default.FtpHost; Semaphore lockOne; lock (_syncRoot) { if (!_connLocks.ContainsKey(ftpHost)) { int semaphorePoolSize = Settings.Default.ConcurentFTPConnectionsCount; lockOne = new Semaphore(0, semaphorePoolSize); lockOne.Release(semaphorePoolSize); _connLocks.Add(ftpHost, lockOne); } else { lockOne = _connLocks[ftpHost]; } } lockOne.WaitOne(); try { bool result = false; FTPConnection conn = new FTPConnection(); conn.Open(Settings.Default.FtpHost, Settings.Default.FtpUserName, Settings.Default.FtpPassword, FTPMode.Passive); conn.SetCurrentDirectory(Settings.Default.FtpTargetFolder); conn.SendFile(item.FileFullPath, FTPFileTransferType.Binary); conn.Close(); result = true; return(result); } finally { lockOne.Release(); } }