Last active
November 3, 2017 15:39
-
-
Save Luc45/0f116cbd2a6e7a8b37aa204e600828c3 to your computer and use it in GitHub Desktop.
Export Filezilla servers and Import it to LastPass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Paste your C:\Users\{user}\AppData\Roaming\FileZilla\sitemanager.xml on $string | |
*/ | |
$string = '<?xml version="1.0"?> | |
<FileZilla3 version="3.28.0" platform="windows"> | |
<Servers> | |
<Server> | |
<Host>something.com</Host> | |
<Port>22</Port> | |
<Protocol>1</Protocol> | |
<Type>0</Type> | |
<User>admin</User> | |
<Pass encoding="base64">MTIz</Pass> | |
<Logontype>1</Logontype> | |
<TimezoneOffset>0</TimezoneOffset> | |
<PasvMode>MODE_DEFAULT</PasvMode> | |
<MaximumMultipleConnections>0</MaximumMultipleConnections> | |
<EncodingType>Auto</EncodingType> | |
<BypassProxy>0</BypassProxy> | |
<Name>something.com</Name> | |
<Comments /> | |
<Colour>0</Colour> | |
<LocalDir /> | |
<RemoteDir /> | |
<SyncBrowsing>0</SyncBrowsing> | |
<DirectoryComparison>0</DirectoryComparison> | |
</Server> | |
<Server> | |
<Host>something.com</Host> | |
<Port>22</Port> | |
<Protocol>1</Protocol> | |
<Type>0</Type> | |
<User>admin</User> | |
<Pass encoding="base64">MTIz</Pass> | |
<Logontype>1</Logontype> | |
<TimezoneOffset>0</TimezoneOffset> | |
<PasvMode>MODE_DEFAULT</PasvMode> | |
<MaximumMultipleConnections>0</MaximumMultipleConnections> | |
<EncodingType>Auto</EncodingType> | |
<BypassProxy>0</BypassProxy> | |
<Name>something.com</Name> | |
<Comments /> | |
<Colour>0</Colour> | |
<LocalDir /> | |
<RemoteDir /> | |
<SyncBrowsing>0</SyncBrowsing> | |
<DirectoryComparison>0</DirectoryComparison> | |
</Server> | |
</Servers> | |
</FileZilla3>'; | |
$xml = simplexml_load_string($string); | |
function generateCSV() | |
{ | |
$csv = ''; | |
$args = func_get_args(); | |
foreach ($args as $arg) { | |
$csv .= $arg.','; | |
} | |
$csv = rtrim($csv, ','); | |
return $csv; | |
} | |
echo 'url,type,username,password,hostname,extra,name,grouping<br>'; | |
foreach ($xml->Servers->Server as $server) { | |
$url = 'http://sn'; // Required to import as Server. https://helpdesk.lastpass.com/en/importing-from-other-password-managers/ | |
$type = isset($server->Keyfile)?'ssh-key':'server'; | |
$username = $server->User; | |
$password = base64_decode($server->Pass); | |
$hostname = $server->Host; | |
if (isset($server->Keyfile)) { | |
$extra = 'Host: '.$hostname.':'.$server->Port.' / Key: '.$server->Keyfile; | |
} else { | |
$extra = ''; | |
} | |
$name = $server->Name; | |
/** | |
* You can optionally add a new key to each of your servers above, to specify which folder should they be added on LastPass. Example: | |
* <Server> | |
* ... | |
* <Group>Work\Client 1</Group> | |
* </Server> | |
* <Server> | |
* ... | |
* <Group>Work\Client 2</Group> | |
* </Server> | |
* <Server> | |
* ... | |
* <Group>Freelancing\Client 3</Group> | |
* </Server> | |
*/ | |
if (isset($server->Group)) { | |
$grouping = $server->Group; | |
} else { | |
$grouping = ''; | |
} | |
echo generateCSV($url, $type, $username, $password, $hostname, $extra, $name, $grouping).'<br>'; | |
} | |
/** | |
* Copy the result in a .txt file and import it to LastPass using "Generic CSV" option | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment