久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 Python 和 ftplib.FTP 從 z/os 下載文本文件

Downloading text files with Python and ftplib.FTP from z/os(使用 Python 和 ftplib.FTP 從 z/os 下載文本文件)
本文介紹了使用 Python 和 ftplib.FTP 從 z/os 下載文本文件的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在嘗試使用 Python 和 ftplib 從 z/os PDS 自動(dòng)下載一些文本文件.

I'm trying to automate downloading of some text files from a z/os PDS, using Python and ftplib.

由于主機(jī)文件是 EBCDIC,我不能簡單地使用 FTP.retrbinary().

Since the host files are EBCDIC, I can't simply use FTP.retrbinary().

FTP.retrlines(),當(dāng)與 open(file,w).writelines 作為回調(diào)一起使用時(shí),當(dāng)然不提供 EOL.

FTP.retrlines(), when used with open(file,w).writelines as its callback, doesn't, of course, provide EOLs.

所以,對(duì)于初學(xué)者來說,我想出了這段對(duì)我來說看起來不錯(cuò)"的代碼,但由于我是一個(gè)相對(duì)的 Python 菜鳥,任何人都可以提出更好的方法嗎?顯然,為了讓這個(gè)問題保持簡單,這不是最終的花里胡哨的事情.

So, for starters, I've come up with this piece of code which "looks OK to me", but as I'm a relative Python noob, can anyone suggest a better approach? Obviously, to keep this question simple, this isn't the final, bells-and-whistles thing.

非常感謝.

#!python.exe
from ftplib import FTP

class xfile (file):
    def writelineswitheol(self, sequence):
        for s in sequence:
            self.write(s+"
")

sess = FTP("zos.server.to.be", "myid", "mypassword")
sess.sendcmd("site sbd=(IBM-1047,ISO8859-1)")
sess.cwd("'FOO.BAR.PDS'")
a = sess.nlst("RTB*")
for i in a:
    sess.retrlines("RETR "+i, xfile(i, 'w').writelineswitheol)
sess.quit()

更新:Python 3.0,平臺(tái)為 Windows XP 下的 MingW.

Update: Python 3.0, platform is MingW under Windows XP.

z/os PDS 具有固定的記錄結(jié)構(gòu),而不是依賴行結(jié)尾作為記錄分隔符.但是,z/os FTP 服務(wù)器在以文本模式傳輸時(shí),會(huì)提供記錄結(jié)尾,而 retrlines() 會(huì)去掉這些結(jié)尾.

z/os PDSs have a fixed record structure, rather than relying on line endings as record separators. However, the z/os FTP server, when transmitting in text mode, provides the record endings, which retrlines() strips off.

結(jié)束更新:

這是我修改后的解決方案,它將成為持續(xù)開發(fā)的基礎(chǔ)(例如,刪除內(nèi)置密碼):

Here's my revised solution, which will be the basis for ongoing development (removing built-in passwords, for example):

import ftplib
import os
from sys import exc_info

sess = ftplib.FTP("undisclosed.server.com", "userid", "password")
sess.sendcmd("site sbd=(IBM-1047,ISO8859-1)")
for dir in ["ASM", "ASML", "ASMM", "C", "CPP", "DLLA", "DLLC", "DLMC", "GEN", "HDR", "MAC"]:
    sess.cwd("'ZLTALM.PREP.%s'" % dir)
    try:
        filelist = sess.nlst()
    except ftplib.error_perm as x:
        if (x.args[0][:3] != '550'):
            raise
    else:
        try:
            os.mkdir(dir)
        except:
            continue
        for hostfile in filelist:
            lines = []
            sess.retrlines("RETR "+hostfile, lines.append)
            pcfile = open("%s/%s"% (dir,hostfile), 'w')
            for line in lines:
                pcfile.write(line+"
")
            pcfile.close()
        print ("Done: " + dir)
sess.quit()

感謝 John 和 Vinay

My thanks to both John and Vinay

推薦答案

我在試圖弄清楚如何從 z/OS 遞歸下載數(shù)據(jù)集時(shí)遇到了這個(gè)問題.多年來,我一直在使用簡單的 python 腳本從大型機(jī)下載 ebcdic 文件.它實(shí)際上就是這樣做的:

Just came across this question as I was trying to figure out how to recursively download datasets from z/OS. I've been using a simple python script for years now to download ebcdic files from the mainframe. It effectively just does this:

def writeline(line):
    file.write(line + "
")

file = open(filename, "w")
ftp.retrlines("retr " + filename, writeline)

這篇關(guān)于使用 Python 和 ftplib.FTP 從 z/os 下載文本文件的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Why I cannot make an insert to Python list?(為什么我不能插入 Python 列表?)
Insert a column at the beginning (leftmost end) of a DataFrame(在 DataFrame 的開頭(最左端)插入一列)
Python psycopg2 not inserting into postgresql table(Python psycopg2 沒有插入到 postgresql 表中)
list extend() to index, inserting list elements not only to the end(list extend() 索引,不僅將列表元素插入到末尾)
How to add element in Python to the end of list using list.insert?(如何使用 list.insert 將 Python 中的元素添加到列表末尾?)
TypeError: #39;float#39; object is not subscriptable(TypeError:“浮動(dòng)對(duì)象不可下標(biāo))
主站蜘蛛池模板: 亚洲系列第一页 | 国产精品自产拍在线观看蜜 | 日韩欧美在线精品 | 欧美三区 | 性色av一区 | 日韩综合在线视频 | 免费特级黄毛片 | 国产精品久久久久久福利一牛影视 | 久久久999精品 | 欧美日韩视频在线第一区 | 日韩免费三级 | 国产 欧美 日韩 一区 | 免费视频中文字幕 | 成人一级视频在线观看 | 91精品国产91久久久久游泳池 | 一区二区三区国产好 | 国产免费一区二区 | 国产一区在线视频 | 波多野结衣一区二区三区在线观看 | 狠狠涩| 成人在线视频一区二区三区 | 日韩欧美视频网站 | 久久久精品网 | 午夜小电影 | 日韩精品中文字幕在线 | 一区二区成人在线 | 亚洲成人中文字幕 | 国产精品视频免费观看 | 欧美嘿咻| 一区二区三区四区国产精品 | 伊人狠狠干 | 欧美9999| 成人不卡在线 | 国产一区二区a | 国内久久| 日韩不卡一区二区 | 草久久 | 神马影院一区二区三区 | 免费欧美 | 久久99久久| 日韩毛片在线观看 |