Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1118748
  • 博文数量: 241
  • 博客积分: 4385
  • 博客等级: 上校
  • 技术积分: 2383
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-07 23:13
文章分类

全部博文(241)

文章存档

2013年(1)

2012年(8)

2011年(62)

2010年(109)

2009年(61)

分类: Python/Ruby

2011-01-25 09:29:33

 

#!/usr/bin/env python

import os, sys
from ftplib import FTP

release_dir = '/pub/I9200_Release/release'
download_path = './'

args = len(sys.argv)
if args >= 2:
    download_path = sys.argv[1]
    
class MyFTP(FTP):
    def __init__(self):    
        self.ftp = FTP().__init__()
        self.i9200_dir = ''
        self.i9200_file = ''
        self.download_file = ''
        
    def loginFtp(self):
        self.ftp = FTP('165.213.149.206')
        self.ftp.login('lin.yuan', 'lin.yuan')
        print "Begin here---------->"
        
    def getDirFile(self):
        self.i9200_dir = self.ftp.nlst(release_dir)[len(self.ftp.nlst(release_dir)) - 1]
        for item in self.ftp.nlst(self.i9200_dir):
            if 'I9200' in item and 'ubi.tar' in item:
                self.i9200_file = item.split('/')[-1]
    
    def checkExist(self, path):
        self.download_file = os.path.join(path, self.i9200_file)
        if os.path.isfile(self.download_file):
            return True
        else:
            return False
                
    def downloadFile(self):
        self.ftp.cwd(self.i9200_dir)
        print "Download %s from %s to %s" % (self.i9200_file, self.i9200_dir, self.download_file)    
        self.ftp.retrbinary('RETR %s' % self.i9200_file, open(self.download_file, 'wb').write)
    
    def quitFtp(self):
        print "End here------------>"
        self.ftp.quit()        

def main():
    ftp = MyFTP()
    ftp.loginFtp()
    ftp.getDirFile()
    if not ftp.checkExist(download_path):
        ftp.downloadFile()
    else:
        print "You have got the latest version!"
    ftp.quitFtp()
        
if __name__ == '__main__':
    main()


阅读(6411) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~