Source (Text):
import ftplib
from string import split
from StringIO import StringIO
host='localhost'
login='runyaga'
password='^%$^@5@#$S'
port=21
def ftp(obj, host=host, login=login, password=password, port=port):
_ftp = ftplib.FTP()
_ftp.connect(host, port)
_ftp.login(login, password)
if lower(obj.meta_type)=='file':
binary=1
if obj.content_type[:4]=='text': binary=0
ftp_file(_ftp, obj, binary)
if lower(obj.meta_type)=='image':
ftp_file(_ftp, obj, 1)
_ftp.quit()
def ftp_file(ftpCon, fileObj, binary):
if binary:
ftpCon.storbinary("STOR " + fileObj.getId(), StringIO(fileObj.data), 1024)
else:
f = StringIO()
f.readlines(split(fileObj.data, '\n'))
f.seek(0)
ftpCon.storlines("STOR " + fileObj.getId(), f)
file=getattr(context, 'index.html')
context.ftp_out(file)
<dtml-call "ftp_out(_.getitem('index.html'))">
context.ftp_out(file, 'ftp.python.org', 'anonymous', 'bob@slack.net', 8021)
|