/// <summary> /// 下载文件 /// </summary> /// <param name="ftpFolder">ftp目录</param> /// <param name="ftpFileName">ftp文件名</param> /// <param name="localFolder">本地目录</param> /// <param name="localFileName">本地文件名</param> public bool GetFile(string ftpFolder, string ftpFileName, string localFolder, string localFileName) { try { if (ftp == null) { ftp = this.getFtpClient(); } if (!ftp.Connected) { ftp.Connect(); ftp.ChDir(ftpFolder); } ftp.Get(ftpFileName, localFolder, localFileName); return(true); } catch { try { ftp.DisConnect(); ftp = null; } catch { ftp = null; } return(false); } }
private void button3_Click(object sender, EventArgs e) { FTPClient FTPClient = new FTPClient(txtIP.Text.Trim(), @"CMM\0001\0001-C403-D02", txtUse.Text.Trim(), txtPW.Text.Trim(), int.Parse(txtport.Text)); FTPClient.Connect(); if (FTPClient.Connected) { //首先进入到目标目录 //FTPClient.ChDir(@"MachRoders\160725"); //FTPClient.RmDir(new DirectoryInfo(@"F:\EACT3.0\EACT3.0\UI\bin\Debug\CNCMACHINE\10000081").Name); FTPClient.Get("0001-C403-D02.stp", @"C:\Users\cj\Desktop\三亚消防", "0001-C403-D02.stp"); } FTPClient.DisConnect(); MessageBox.Show("OK"); }
private void TcpD_Click(object sender, EventArgs e) { FolderBrowserDialog FB = new FolderBrowserDialog(); FB.Description = "选择将文件夹保存到本地文件夹"; if (FB.ShowDialog() == System.Windows.Forms.DialogResult.OK) { FTPClient FTPClient = new FTPClient("192.168.1.30", "", "eact", "123", 21); FTPClient.Connect(); if (FTPClient.Connected) { var ee = FTPClient.List("-a"); } FTPClient.DisConnect(); MessageBox.Show("OK"); } }
private void button2_Click(object sender, EventArgs e) { OpenFileDialog FB = new OpenFileDialog(); FB.Multiselect = false; if (FB.ShowDialog() == System.Windows.Forms.DialogResult.OK) { FTPClient FTPClient = new FTPClient(txtIP.Text.Trim(), "", txtUse.Text.Trim(), txtPW.Text.Trim(), int.Parse(txtport.Text)); FTPClient.Connect(); if (FTPClient.Connected) { //首先进入到目标目录 //FTPClient.ChDir(@"MachRoders\160725"); //FTPClient.RmDir(new DirectoryInfo(@"F:\EACT3.0\EACT3.0\UI\bin\Debug\CNCMACHINE\10000081").Name); FTPClient.Put(FB.FileName); } FTPClient.DisConnect(); MessageBox.Show("OK"); } }
private void TcpU_Click(object sender, EventArgs e) { FolderBrowserDialog FB = new FolderBrowserDialog(); FB.Description = "选择需要上传的文件夹"; if (FB.ShowDialog() == System.Windows.Forms.DialogResult.OK) { FTPClient FTPClient = new FTPClient(txtIP.Text.Trim(), "", txtUse.Text.Trim(), txtPW.Text.Trim(), 21); FTPClient.Connect(); if (FTPClient.Connected) { //首先进入到目标目录 //FTPClient.ChDir(@"MachRoders\160725"); //FTPClient.RmDir(new DirectoryInfo(@"F:\EACT3.0\EACT3.0\UI\bin\Debug\CNCMACHINE\10000081").Name); FTPClient.Put(FB.SelectedPath, "*"); } FTPClient.DisConnect(); MessageBox.Show("OK"); } }
private void Init() { //创建下载文件夹 if (!Directory.Exists("D:\\FtpDownload")) { Directory.CreateDirectory("D:\\FtpDownload"); } string path = "D:\\FtpDownload\\" + imageID; if (!File.Exists(path)) { ftpClient = new FTPClient(); //连接FTP服务器 if (ftpClient.Connected) { ftpClient.DisConnect(); } ftpClient.FTPClientPram("109.116.6.5", creatDT, "pacsuser", "pacs2014", 522); ftpClient.SetTransferType(FTPClient.TransferType.Binary); ftpClient.Get(imageID, "D:\\FtpDownload", ""); } pictureEdit1.Image = Image.FromFile(path, false); }
private void GetFTPData(DateTime currentDate) { m_localFolder = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "temp/BI_CustomerFlow/FTPData/" + currentDate.ToShortDateString(); FTPClient client = new FTPClient("192.168.0.26", "", "jk", "jk654@123", 21); client.Connect(); GetFolder("*", ".ep01", client, CreateFolder(), currentDate); //由于 FTP的数据有滞后,所以需要缓冲一天的数据 //GetFolder("*", ".ep01", client, CreateFolder(), "BRK.PCNT.Site Name." + currentDate.AddDays(1).ToString("yyMMdd")); client.DisConnect(); //ClearFolder() Console.WriteLine("下载完毕"); m_dtFTP = new BI_CustomerFlow.T_CustomerFlowDataTable(); m_dtFTP.Columns.Remove("Seq_No"); //获取数据 foreach (string strFileName in Directory.GetFiles(m_localFolder)) { FileStream fs = new FileStream(strFileName, FileMode.Open, FileAccess.Read); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, (Int32)fs.Length); fs.Close(); fs.Close(); fs.Close(); fs.Dispose(); fs.Dispose(); fs.Dispose(); string[] strText = Encoding.UTF8.GetString(buffer).Replace("\r\n", "\n").Split('\n'); //案例数据:25||Site ID||New Zone0|2|09/11/2013 04:00:00|1|1|160|159|192.168.254.2| foreach (string strRow in strText) { if (strRow == "") { continue; } string strTemp = ""; if (strRow.Substring(strRow.Length - 1) == "|") { strTemp = strRow.Substring(0, strRow.Length - 1); } string[] str = (System.Guid.NewGuid().ToString() + "|" + strTemp).Split('|'); //错误数据 if (str.Length != 13) { continue; } if (str[7].StartsWith(currentDate.ToString("MM/dd/yyyy"))) { m_dtFTP.Rows.Add(str); } } } }