public void test() { if (Directory.Exists(workingDirectory)) { Directory.Delete(workingDirectory, true); Directory.CreateDirectory(workingDirectory); } else { Directory.CreateDirectory(workingDirectory); } using (ftp = new FtpConnection(txtServername.Text,21, txtUsername.Text, txtPassword.Text)) { ftp.Open(); /* Open the FTP connection */ ftp.Login(); /* Login using previously provided credentials */ if (ftp.DirectoryExists(txtRootDir.Text)) /* check that a directory exists */ { ftp.SetCurrentDirectory(txtRootDir.Text); /* change current directory */ } // StreamReader reader = new StreamReader(txtBrowse.Text); try { string line = string.Empty; FtpDirectoryInfo info = ftp.GetCurrentDirectoryInfo(); fileInfos = info.GetFiles(); foreach (FtpFileInfo item in fileInfos) { //ftp.GetFile(item.Name, Directory.GetCurrentDirectory() + @"\Output\" + line + @"\item.Name", false); ListboxItem listBoxItem = new ListboxItem(); listBoxItem.fileName = item.Name; listBoxItem.filePath = txtRootDir.Text + item.Name; lstFiles.Items.Add(listBoxItem); } //ftp.SetCurrentDirectory(@"/loth2/itsred/caixa/3.1.22.PROD"); ftp.SetLocalDirectory(workingDirectory); ftp.GetFile(fileInfos[1].Name,false); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { ftp.Close(); } } }
private void GetFilesByFtp(string host, string remoteLocation) { List<string> remoteFiles = new List<string>(); string localDownloadDirectory = string.Empty; FtpConnection connection = new FtpConnection(host, "mxftp", "mxftp"); try { try { connection.Open(); } catch (Exception ex) { CommonUtils.ShowError(ex.Message, ex); } connection.Login(); connection.SetCurrentDirectory(remoteLocation); FtpFileInfo[] ftpFileInfo = connection.GetFiles("*act.rftvp"); ScriptName = connection.GetCurrentDirectoryInfo().Name; localDownloadDirectory = downloadDir + ScriptName; //if(Directory.Exists(localDownloadDirectory)){ // Directory.Delete(localDownloadDirectory,true); // } DirectoryInfo downloadDirectoryInfo = Directory.CreateDirectory(localDownloadDirectory); connection.SetLocalDirectory(downloadDirectoryInfo.FullName); for (int i = 0; i < ftpFileInfo.Length; i++) { connection.GetFile(ftpFileInfo[i].Name, false); } } finally { connection.SetLocalDirectory(Path.GetTempPath()); connection.Close(); connection.Dispose(); } ReplaceFiles(localDownloadDirectory, txtDest.Text); //deleting local files //Directory.Delete(localDownloadDirectory); }