import ftplib import os import socket HOST='192.168.30.109' FILE='test' def main(): try: f=ftplib.FTP(HOST) except (socket.error,socket.gaierror),e: print 'ERROR:cannot reach "%s"'% HOST return print '***connected to host "%s"' % HOST try: f.login(user='test',passwd='123') except ftplib.error_perm: print 'ERROR:cannot login anonymously' f.quit() return print '***Logged in as "test""' try: f.retrbinary('RETR %s' % FILE,open(FILE,'wb').write) except ftplib.error_perm: print 'ERROR:cannot read file "%s"' % FILE os.unlink(FILE) else: print '***Downloaded "%s" to CWD' % FILE return try: f.storbinary('STOR %s' % FILE,open(FILE,'rb')) except ftplib.error_perm: print 'ERROR:cannot up file "%s"' % FILE os.unlink(FILE) else: print '***upload "%s" to ftp' % FILE f.quit() return if __name__=='__main__': main()
posted on 2011-12-05 18:20 h2内存数据库 阅读(1460) 评论(0) 编辑 收藏 举报