def main():
    # endpoint to connect to
    url = 'data.asc-csa.gc.ca'
    path = '/users/OpenData_DonneesOuvertes/pub/MOPITT'

    # change to your paths
    csvpath = "/home/benjo/ausbildung/fhsalzburg/6.Semester/deepData/orbital-penguin/pipeline/data/MOPITT/2019"
    jsonpath = "./co2"
    try:
        pipeline = FtpClient(url, path)
        print("start converting to json")
        pipeline.convertCsv(csvpath, jsonpath)
    except Exception as e:
        print(e)
Пример #2
0
def main(argv):
    try:
        opts,args=getopt.getopt(argv,"f:d:o:tr:b:",["ftp=","dir=","opt=","tmp","remote=","bak=="])
    except getopt.GetoptError:          
        usage()                         
        sys.exit(2)
    host,port,user,pwd='',21,'',''
    tmp,local,remotedir,bak=os.path.dirname(__file__),'','./' ,''
    o=''
    print opts
    for opt,arg in opts:
        if opt in ['-f','--ftp']:
            cfg=Config(arg)
            host=cfg.str('host')
            port=cfg.int('port',21)
            user=cfg.str('user')
            pwd=cfg.str('pwd')
        elif opt in ['-o','--opt']:
            o=arg
        elif opt in ['-d','--dir']:
            local=arg
        elif opt in ['-t','--tmp']:
            tmp=arg
        elif opt in ['-r','--remote']:
            remotedir=arg
        elif opt in ['-b','--bak']:
            bak=arg
        else:
            print u'未知参数:'+opt
            usage()                         
            sys.exit(2)

    if o not in ['down','up']:
        print u'-o/--opt参数不正确。',o
        usage()                         
        sys.exit(2)
    ftp_args={'host':host,'port':port,'user':user,'pwd':pwd}
    client=FtpClient(**ftp_args)
    client.login()
    if o == 'down':
        down(client,remotedir,local,tmp)
    else:
        up(client,local,remotedir,bak,ftp_args)
    sys.exit(0)
Пример #3
0
     if file.endswith('.zip'):
         ftp.del_file(file.split()[-1])             #清除服务器文件
         print 'DEL',file
 ftp.close()
 #remote=str(uuid.uuid1()).replace('-','')+'.zip'
 f=FileItem(local)
 zippath=os.path.join(bak,'delta.zip')
 if not os.path.exists(zippath):
     try:
         f.zipto(zippath)
         print 'compress success'
     except Exception,e:
         print str(e)
         pass
 #重新登录
 ftp=FtpClient(**ftp_args)
 ftp.login()
 ftp.cwd(remotedir)
 now=datetime.datetime.now()
 bakfile=str(now).replace('-','').replace(':','').replace('.','').replace(' ','') + '.zip'
 remote=bakfile
 retry=0
 is_upload_ok=False
 while retry<=10:
     try:
         is_upload_ok=ftp.upload_file(zippath,remote)
         if is_upload_ok:
             break;
         else:
             ftp.del_file(remote)
     except Exception,e: