public static bool lfDirectorioInsertaOValidaRutaFTP(ref string sPATH) { sPATH = sPATH.Replace(@"\\", @"//"); sPATH = sPATH.Replace(@"\", @"/"); bool bandera = false; string sRutaPATH = string.Empty; string sUsuario = string.Empty; string sPWD = string.Empty; string sRutaRelativa = string.Empty; sRutaPATH = @sPATH.Split('/')[2].ToString(); for (int iRelativo = 0; iRelativo < @sPATH.Split('/').Length; iRelativo++) { if (iRelativo > 2) @sRutaRelativa += @sPATH.Split('/')[iRelativo] + "/"; } //if (sRutaPATH == "189.206.75.142") //{ sUsuario = ConfigurationManager.AppSettings["FTPUser"].ToString(); sPWD = ConfigurationManager.AppSettings["FTPPwd"].ToString(); //} try { int iDOLimit = 0; do { FtpClient clienteftp = new FtpClient("ftp://" + sRutaPATH, @sUsuario, @sPWD, 21); WebException ex = new WebException(); bandera = clienteftp.DirectoryExits(sRutaRelativa, out ex); if (!bandera) clienteftp.CreateDirectoryRecursive(sRutaRelativa, out ex); if (!bandera) clienteftp.CreateDirectoryRecursive(sRutaRelativa, out ex); if (!bandera) iDOLimit++; else return bandera; } while (iDOLimit <= 2); } catch (WebException ex) { Console.Write(ex.Message); return false; } return true; }