private void timedSending(object Sender, EventArgs e) { logs += "Sending Files......."; label10.Visible = true; textBox8.Text += logs + Environment.NewLine; saveLog(logs); logs = ""; var uri = new Uri("ftp://" + confList["Server"]); /* Create Object Instance */ ftp ftpClient = new ftp(uri.ToString(), confList["Username"], confList["Password"]); string newFolder = confList["Fpath"] + "/" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"); if (radioButton3.Checked) { newFolder = newFolder + "_" + textBox13.Text + "_UPPER"; } else { newFolder = newFolder + "_" + textBox13.Text + "_LOWER"; } System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; ftpClient.createDirectory(newFolder); recursiveDirectory(textBox4.Text, newFolder, ftpClient); System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; updateTreeView(); label10.Visible = false; }
private void recursiveDirectory(string dirPath, string uploadPath, ftp ftpClient) { string[] files = Directory.GetFiles(dirPath, "*.*"); string[] subDirs = Directory.GetDirectories(dirPath); foreach (string file in files) { string dateCreat = ftpClient.getFileCreatedDateTime(uploadPath + "/" + Path.GetFileName(file)); if (dateCreat != File.GetCreationTime(file).ToString()) { ftpClient.delete(uploadPath + "/" + Path.GetFileName(file)); logs = ftpClient.upload(uploadPath + "/" + Path.GetFileName(file), file); } else { //logs = ftpClient.upload(uploadPath + "/" + Path.GetFileName(file), file); } textBox8.Text += logs + Environment.NewLine; saveLog(logs); logs = ""; } foreach (string subDir in subDirs) { ftpClient.createDirectory(uploadPath + "/" + Path.GetFileName(subDir)); recursiveDirectory(subDir, uploadPath + "/" + Path.GetFileName(subDir), ftpClient); } }
string pegaArq() { String ftpServerIP = ConfigurationManager.AppSettings["ftpServerIP"]; String ftpUserID = ConfigurationManager.AppSettings["ftpUserID"]; String ftpPassword = ConfigurationManager.AppSettings["ftpPassword"]; /* Create Object Instance */ // ftp ftpClient = new ftp(@"ftp://10.10.10.10/", "user", "password"); ftp ftpClient = new ftp(ftpServerIP, ftpUserID, ftpPassword); /* Upload a File */ ftpClient.upload("etc/test.txt", @"C:\Users\metastruct\Desktop\test.txt"); /* Download a File */ ftpClient.download("etc/test.txt", @"C:\Users\metastruct\Desktop\test.txt"); /* Delete a File */ ftpClient.delete("etc/test.txt"); /* Rename a File */ ftpClient.rename("etc/test.txt", "test2.txt"); /* Create a New Directory */ ftpClient.createDirectory("etc/test"); /* Get the Date/Time a File was Created */ string fileDateTime = ftpClient.getFileCreatedDateTime("etc/test.txt"); Console.WriteLine(fileDateTime); /* Get the Size of a File */ string fileSize = ftpClient.getFileSize("etc/test.txt"); Console.WriteLine(fileSize); /* Get Contents of a Directory (Names Only) */ string[] simpleDirectoryListing = ftpClient.directoryListDetailed("/etc"); for (int i = 0; i < simpleDirectoryListing.Count(); i++) { Console.WriteLine(simpleDirectoryListing[i]); } /* Get Contents of a Directory with Detailed File/Directory Info */ string[] detailDirectoryListing = ftpClient.directoryListDetailed("/etc"); for (int i = 0; i < detailDirectoryListing.Count(); i++) { Console.WriteLine(detailDirectoryListing[i]); } /* Release Resources */ ftpClient = null; return("ok"); }
public bool SubirArchivosAlServidor(string cliente_id, string tipo_documento, string nombre_archivo) { try { DS_FacturacionElectronica.tipo_documentoDataTable dtTipoDocumento = new DS_FacturacionElectronica.tipo_documentoDataTable(); tipo_documentoTableAdapter taTipoDocumento = new tipo_documentoTableAdapter(); taTipoDocumento.Fill(dtTipoDocumento); ftp FtpClient = new ftp(); FtpClient.createDirectory(Configuraciones.RutaRepositorioFTP + "/" + cliente_id); foreach (var item in dtTipoDocumento) { FtpClient.createDirectory(Configuraciones.RutaRepositorioFTP + "/" + cliente_id + "/" + item.CODIGO); } string ext = ""; for (int i = 0; i < 2; i++) { switch (i) { case 0: ext = ".pdf"; break; case 1: ext = ".xml"; break; } FtpClient.upload(Configuraciones.RutaRepositorioFTP + "/" + cliente_id + "/" + tipo_documento + "/" + nombre_archivo + ext, this.RepositorioLocal(cliente_id, tipo_documento) + "/" + nombre_archivo + ext); } return(true); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); } return(false); }