I originally read about this script here. ย Decided to include the script below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
#!/usr/bin/php <? /* This script takes a config file from WS_FTP (WS_FTP.ini) and converts it to filezilla format Version 1.0 Author: Andrew Kerr (andrew@arrkerr.com) Credit is given where due in the function headers I make no claims about this program, use it at your own risk. If for some reason anything in this script violates any rules on the part of wsftp or filezilla, please do not use it and let me know so that I can remove it. */ if ($argc != 2) { die(“Usage: “. $argv[0] .” <wsftp config file>\n”); } $inFile = $argv[1]; $outFile = “FileZilla.xml”; // open up the input file if (!$inFH = fopen($inFile, “r”)) { die(“Unable to open the wsftp config file\n”); } // open up the output file if (!$outFH = fopen($outFile, ‘w’)) { die(“Unable to open the wsftp config file\n”); } // a variable to keep track of if we’re working on the very first host or not $firstHost = true; // print the config file header printHeader($outFH); // loop through the file one line at a time while ($currentLine = fgets($inFH)) { // check for an empty line if (strLen($currentLine) > 1) { // if the line starts with a [ then it is a new site, and a new site name if (substr($currentLine,0,1) == “[“) { if ($firstHost == false) { //write out the site config writeSite($siteName, $hostName, $userName, $password, $remoteDir, $passive, $outFH); } $firstHost = false; $siteName = ltrim(trim(rtrim($currentLine), “\]”), “\[“); } // otherwise it is a parameter to a previous site name else { // seperate the paramter from the value list($param, $val) = split(“=”, $currentLine, 2); switch ($param) { case “HOST”: $hostName = chop($val); break; case “rdir0”: $remoteDir = chop($val); break; case “UID”: $userName = chop($val); break; case “PWD”: $password = encryptFilezilla(decryptWSFTP(“PWD=” . chop($val))); break; case “PASVMODE”: $passive = chop($val); break; } } } } // write out the last site once we hit the end of the file if ($firstHost == false) { //write out the site config writeSite($siteName, $hostName, $userName, $password, $remoteDir, $passive, $outFH); } // print the footer printFooter($outFH); // close the input and output files fclose($inFH); fclose($outFH); /* Write the filezilla site config */ function writeSite($siteName, $hostName, $userName, $password, $remoteDir, $passive, $outFH) { if (($passive != 0) && ($passive != 1)) { // If PASVMODE was blank in the WS_FTP config (which it wouldn’t ever be?) set it to 0 // 0 in FileZilla is “default” $passive = 0; } if ($passive = 0) { // WS_FTP uses 0 for active, FileZilla uses 2 $passive = 2; } // $passive=2; // if you need to convert everything to active (I did because of our firewall) fwrite($outFH, ‘<Site Name=”‘ . $siteName . ‘” Host=”‘ . $hostName . ‘” Port=”21″ User=”‘ . $userName . ‘” Account=”” RemoteDir=’. $remoteDir .‘ LocalDir=”” Pass=”‘ . $password . ‘” Logontype=”1″ FWBypass=”0″ DontSavePass=”0″ ServerType=”” PasvMode=”‘ . $passive . ‘” TimeZoneOffset=”0″ TimeZoneOffsetMinutes=”0″ Comments=”” UTF8=”0″ DefaultSite=”0″ />’ . “\n”); } /* Convert the ws_ftp password to plain-text Converted from the javascript version at: http://www.tele-pro.co.uk/software/ws%5Fftp%5Fpass/ */ function decryptWSFTP($str) { $out = “”; $pw = substr($str, 37, strlen($str)); for ($i=0; $i<(strlen($pw)/2); $i++) { $character = substr($pw, $i*2, 2); $sal = substr($str, 5+$i, 1); $claro = (“0x”. $character)–$i–1–((47+parseInt(“0x” . $sal))%57); $out = $out . chr($claro); } return $out; } /* php version of the javascript parseInt() function that convers an int to a char */ function parseInt($data) { return intval(substr($data,0,8),16); } /* Convert a plain-text password to filezilla format Based on a version from http://www.sourceshock.com/details_snippet/39/ */ function encryptFilezilla($str) { $encryptionKey = “FILEZILLA1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ”; $pos = strlen($str) % strlen($encryptionKey); $ret = “”; for ($i=0; $i<strlen($str); $i++) { $x = sprintf(“%s”,$str[$i] ^ $encryptionKey[($i + $pos) % strlen($encryptionKey)]); if (preg_match(“/[^a-z]/”,$str[$i])) { $min = 3 – strlen(ord($x)); $z = str_repeat(‘0’,$min) . ord($x); } else { $z = “0” . ord($x); } $ret .= $z; } return $ret; } /* Print the filezilla config file footer */ function printFooter($outFH) { fwrite($outFH, ‘</Sites>’ . “\n” . ‘<Settings>’ . “\n” . ‘</Settings>’ . “\n” . ‘<RecentServers/>’ . “\n” . ‘</FileZilla>’ . “\n”); } /* Print the filezilla config file header */ function printHeader($outFH) { fwrite($outFH, ‘<?xml version=“1.0” encoding=“ISO-8859-1”?>‘ . “\n” . ‘<FileZilla>‘. “\n” . ‘<Sites>‘. “\n”); } ?> |
Leave a Reply