| 1 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | // FILE : sftp.tol |
|---|
| 3 | // PURPOSE : Funciones para realizar "ftp" de forma segura. |
|---|
| 4 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 5 | |
|---|
| 6 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 7 | // SFtp common functions |
|---|
| 8 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 9 | |
|---|
| 10 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 11 | Text SFtpFiles(Text localDir, // Directorio local |
|---|
| 12 | Text relDir, // Directorio relativo al local |
|---|
| 13 | Text filPattern, // Patron de los ficheros |
|---|
| 14 | Text tarFile, // Archivo donde empaquetar los ficheros |
|---|
| 15 | Real toLower, // Envio de nombre en minusculas |
|---|
| 16 | Real casSen) // Equiparacion sensible a mayus/minusculas |
|---|
| 17 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 18 | { |
|---|
| 19 | Set getDir = GetDir(localDir+relDir); |
|---|
| 20 | Set filSet = getDir[1]; |
|---|
| 21 | Set dirSet = getDir[2]; |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | Set filList = EvalSet(filSet, Text(Text fil) |
|---|
| 25 | { |
|---|
| 26 | If(TextMatch(fil,filPattern,casSen), |
|---|
| 27 | { |
|---|
| 28 | Text filName = If(toLower, ToLower(fil), fil); |
|---|
| 29 | AppendFile("sftp_"+localDirRoot+".bat", |
|---|
| 30 | "tar rvf "+"sftp_"+localDirRoot+".tar "+relDir+"/"+filName+"\n"); |
|---|
| 31 | AppendFile("sftp_"+localDirRoot+".sh", |
|---|
| 32 | "tar rvf "+"sftp_"+localDirRoot+".tar "+relDir+"/"+filName+"\n"); |
|---|
| 33 | "" |
|---|
| 34 | }, "") |
|---|
| 35 | }); |
|---|
| 36 | |
|---|
| 37 | Set subdirList = EvalSet(dirSet, Text(Text subDir) |
|---|
| 38 | { |
|---|
| 39 | Text dirName = If(toLower, ToLower(subDir), subDir); |
|---|
| 40 | SFtpFiles(localDir+"/"+dirName, relDir+"/"+dirName, filPattern, |
|---|
| 41 | tarFile, toLower, casSen) |
|---|
| 42 | }); |
|---|
| 43 | |
|---|
| 44 | "" |
|---|
| 45 | }; |
|---|
| 46 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 47 | PutDescription( |
|---|
| 48 | "En el fichero especificado commandFile, añade las ordenes necesarias para |
|---|
| 49 | comprimir los ficheros de localDir que coinciden con un patron (pattern) |
|---|
| 50 | en el fichero tarFile y recursivamente hace lo mismo para cada subdirectorio |
|---|
| 51 | Si toLower es TRUE toma los nombres de ficheros siempre en minusculas. |
|---|
| 52 | Si casSen es TRUE el match de fichero se realiza sensible a mayusculas y |
|---|
| 53 | minusculas.", |
|---|
| 54 | SFtpFiles); |
|---|
| 55 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 59 | Real SFtpBuild(Text hostRootDir, // Directorio remoto |
|---|
| 60 | Text localDir, // Directorio local del web |
|---|
| 61 | Text localDirRoot, // Raiz del directorio local |
|---|
| 62 | Set filPatterns, // Conjunto de patrones de los ficheros |
|---|
| 63 | Text host, // Nombre del host remoto |
|---|
| 64 | Text user, // Nombre del usuario remoto |
|---|
| 65 | Text password, // Palabra clave de acceso |
|---|
| 66 | Real toLower, // Envio de ficheros en minusculas |
|---|
| 67 | Real casSen) // Sensible a mayus/minusculas |
|---|
| 68 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 69 | { |
|---|
| 70 | Text WriteFile("sftp_"+localDirRoot+".bat", "cd "+localDir+"\n"); |
|---|
| 71 | Text WriteFile("sftp_"+localDirRoot+".sh", "cd "+localDir+"\n"); |
|---|
| 72 | |
|---|
| 73 | Set EvalSet(filPatterns, Text(Text pattern) |
|---|
| 74 | { |
|---|
| 75 | SFtpFiles(localDir, localDirRoot, pattern, "SFtp.tar", |
|---|
| 76 | toLower, casSen) |
|---|
| 77 | }); |
|---|
| 78 | |
|---|
| 79 | Text AppendFile("sftp_"+localDirRoot+".bat", |
|---|
| 80 | "gzip sftp_"+localDirRoot+".tar\n"); |
|---|
| 81 | Text AppendFile("sftp_"+localDirRoot+".sh", |
|---|
| 82 | "gzip sftp_"+localDirRoot+".tar\n"); |
|---|
| 83 | Text AppendFile("sftp_"+localDirRoot+".bat", |
|---|
| 84 | "psftp "+user+"@"+host+":"+hostRootDir+ |
|---|
| 85 | " sftp_"+localDirRoot+".tar.gz\n"); |
|---|
| 86 | Text AppendFile("sftp_"+localDirRoot+".sh", |
|---|
| 87 | " sftp_"+localDirRoot+".tar.gz\n" |
|---|
| 88 | +user+"@"+host+":"+hostRootDir+"\n"); |
|---|
| 89 | // Text AppendFile("sftp_"+localDirRoot+".bat", "ssh "+user+"@"+host+ |
|---|
| 90 | // " 'cd "+hostRootDir+"; tar xzvpf SFtp.tar.gz"+"'\n"); |
|---|
| 91 | Text AppendFile("sftp_"+localDirRoot+".sh", "ssh "+user+"@"+host+ |
|---|
| 92 | " 'cd "+hostRootDir+"; tar xzvpf SFtp.tar.gz"+"'\n"); |
|---|
| 93 | 0.0 |
|---|
| 94 | }; |
|---|
| 95 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 96 | PutDescription( |
|---|
| 97 | "Crea dos scripts de nombres commandFile con extension .bat y .sh |
|---|
| 98 | para entorno windows y linux respect. con las instrucciones necesarias para |
|---|
| 99 | enviar todos los ficheros que hacen match con filPattern de un directorio |
|---|
| 100 | local (localDir) y de sus subdirectorios. |
|---|
| 101 | Hay que proporcionarle el nombre del host, el usuario (user) y el password y |
|---|
| 102 | el nombre del directorio remoto (hostRootDir) bajo el cual se requiere hacer |
|---|
| 103 | la copia de lo que haya en el subdirectorio localDirRoot de localDir |
|---|
| 104 | localDir/localDirRoot hostRootDir |
|---|
| 105 | / | \ -> / | \ |
|---|
| 106 | a b c a b c |
|---|
| 107 | Si toLower es minuscula todos los nombres de ficheros y subdirectorios son |
|---|
| 108 | enviados en minusculas, esto es clasico para sistemas UNIX. |
|---|
| 109 | Si casSen es TRUE el math de fichero se realizar sensible a mayusculas y |
|---|
| 110 | minusculas.", |
|---|
| 111 | SFtpBuild); |
|---|
| 112 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|