最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

通過python下載FTP上的文件夾的實現(xiàn)代碼

 更新時間:2013年02月10日 10:29:58   作者:  
使用python下載FTP上的文件夾的代碼,有需要的朋友不妨看看
復(fù)制代碼 代碼如下:

# -*- encoding: utf8 -*-
import os
import sys
import ftplib
class FTPSync(object):
    def __init__(self):
        self.conn = ftplib.FTP('10.22.33.46', 'user', 'pass')
        self.conn.cwd('/')        # 遠端FTP目錄
        os.chdir('/data/')        # 本地下載目錄
    def get_dirs_files(self):
        u''' 得到當前目錄和文件, 放入dir_res列表 '''
        dir_res = []
        self.conn.dir('.', dir_res.append)
        files = [f.split(None, 8)[-1] for f in dir_res if f.startswith('-')]
        dirs = [f.split(None, 8)[-1] for f in dir_res if f.startswith('d')]
        return (files, dirs)
    def walk(self, next_dir):
        print 'Walking to', next_dir
        self.conn.cwd(next_dir)
        try:
            os.mkdir(next_dir)
        except OSError:
            pass
        os.chdir(next_dir)
        ftp_curr_dir = self.conn.pwd()
        local_curr_dir = os.getcwd()
        files, dirs = self.get_dirs_files()
        print "FILES: ", files
        print "DIRS: ", dirs
        for f in files:
            print next_dir, ':', f
            outf = open(f, 'wb')
            try:
                self.conn.retrbinary('RETR %s' % f, outf.write)
            finally:
                outf.close()
        for d in dirs:
            os.chdir(local_curr_dir)
            self.conn.cwd(ftp_curr_dir)
            self.walk(d)
    def run(self):
        self.walk('.')
def main():
    f = FTPSync()
    f.run()
if __name__ == '__main__':
    main()

相關(guān)文章

最新評論

卢龙县| 连云港市| 龙川县| 景谷| 永顺县| 成武县| 乌拉特中旗| 邵阳县| 奉新县| 登封市| 莲花县| 偏关县| 东源县| 通化市| 崇仁县| 佛教| 策勒县| 禹城市| 定日县| 湄潭县| 南皮县| 改则县| 乳山市| 玉林市| 潍坊市| 无棣县| 绥芬河市| 承德县| 正安县| 铜山县| 义乌市| 武邑县| 伊宁市| 澎湖县| 邵阳市| 遂昌县| 祁阳县| 广德县| 年辖:市辖区| 故城县| 阿拉尔市|