PDA

View Full Version : my latest creation


inkedmn
03-14-2002, 06:10 PM
i coded this last night


#!/usr/bin/env python

import ftplib

try:
ftpconnect = ftplib.FTP()

server = 'ftp.python.org'
user = 'anonymous'
password = 'inkedmn@gmx.net'

ftpconnect.connect(server, 21)
print "connecting to %s" % server

ftpconnect.login(user, password)
print "logging in..."

welcome = ftpconnect.getwelcome()
print welcome

ftpconnect.cwd('pub/www.python.org')
print "changing to target directory..."

filesize = ftpconnect.size('robots.txt')
print "the file size is %i bytes" % filesize

print "getting text file..."
ftpconnect.retrbinary("RETR robots.txt", open('ftptest.txt', 'w').write)

ftpconnect.quit()
print "sending 'quit' message"

print "operation complete. thank you for your business"

except ftplib.error_perm, message:
print message

except ftplib.error_temp, message:
print message

except ftplib.error_reply, message:
print message



comments?

kmj
03-14-2002, 09:58 PM
sweet. :)

inkedmn
04-02-2002, 06:44 PM
thanks :)

i'd like to eventually develop a full-fledged ftp client in python (CLI), i don't think it'd be too terribly difficult...

kmj
04-02-2002, 09:49 PM
that'd be a cool project. I'm sure you could do it.

inkedmn
04-04-2002, 12:18 PM
wrote this one last night...


#!/usr/bin/env python

import poplib, getpass, string
try:
mailserver = raw_input("Enter your mailserver: ")
server = poplib.POP3(mailserver)
print server.getwelcome()
username = raw_input("Username: ")
server.user(username)
password = getpass.getpass("Password: ")
server.pass_(password)
nummessages = len(server.list()[1])
print "Login successful, checking for messages..."
if nummessages > 0:
print "you have %i messages" % nummessages
else:
print "you have no messages"
print "Disconnecting..."
server.quit()
except Exception, e:
print str(e)


it's alright, whatever.

kmj
04-04-2002, 02:54 PM
qool, getpass. I'll have to remember that.

inkedmn
04-11-2002, 12:38 AM
yeah, it's pretty cool. all it does is just doesn't echo the password back to you.

(pretty sure kmj knew that, but i thought i'd just say it for the benefit of others) :D