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"); }