Literatur:
Um von Python aus Passwörter aus der KDE-Brieftasche zu lesen genügen diese paar Zeilen:
import keyring
# Setzen des Passwortes
keyring.set_password("ftp.wlsoft.de","wlsoft.de", "123")
# Lesen des Passwortes
password = keyring.get_password("ftp.wlsoft.de","wlsoft.de")
Oder hier am Beispiel eines Scripts zum Hochladen einer Datei per FTP auf diesen Server.
import keyring
KEYRING_SERVICE = "ftp.wlsoft.de"
KEYRING_USERNAME = "wlsoft.de"
def main():
if len(sys.argv) < 2:
sys.exit('Usage: %s filename' % sys.argv[0])
filename = sys.argv[1]
if not os.path.exists(filename):
sys.exit('ERROR: File %s was not found!' % filename)
ftp_host = KEYRING_SERVICE
ftp_user = KEYRING_USERNAME
#Das Passwort aus Standard-Keyring lesen (unter KDE ist das kwallet)
ftp_pass = keyring.get_password(KEYRING_SERVICE,KEYRING_USERNAME)
if (ftp_pass==''):
sys.exit('Set Keyring Password for SERVICE %s USERNAME %s' % (KEYRING_SERVICE,KEYRING_USERNAME))
ftp = FTP(ftp_host, ftp_user, ftp_pass)
ftp.cwd("/downloads/htdocs/")
s,n = os.path.split(filename)
s = 'STOR %s' % (n)
#print s
ftp.storbinary(s, open(filename, 'rb'))
return 0
if __name__ == '__main__':
main()
Tags: Python KDE4 FTP