久久久久久久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 下載文本文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

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

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

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

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

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

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

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

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,平臺為 Windows XP 下的 MingW.

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

z/os PDS 具有固定的記錄結(jié)構(gòu),而不是依賴行結(jié)尾作為記錄分隔符.但是,z/os FTP 服務(wù)器在以文本模式傳輸時,會提供記錄結(jié)尾,而 retrlines() 會去掉這些結(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ù)集時遇到了這個問題.多年來,我一直在使用簡單的 python 腳本從大型機下載 ebcdic 文件.它實際上就是這樣做的:

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 下載文本文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(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:“浮動對象不可下標)
主站蜘蛛池模板: 97精品超碰一区二区三区 | 久久久久久久网 | 欧美日批| 免费人成在线观看网站 | 国产精品18久久久 | 国产精品中文字幕在线 | 国产激情视频网站 | 欧美日韩高清一区二区三区 | 午夜免费视频观看 | 日本91av视频| 日韩成人一区 | 精品视频在线免费观看 | 一级片网址 | 日韩a在线| 综合久久综合久久 | 涩涩鲁亚洲精品一区二区 | 麻豆av片 | 久久成人一区 | 99福利在线观看 | 91精品国产91久久久久久 | 国产免费色 | 欧美一级片久久 | 欧美在线观看一区 | 天天操天天插 | 亚洲视频一区在线观看 | 国产人成在线观看 | 欧美日韩成人网 | 午夜爽爽爽男女免费观看影院 | 一区二区三区免费 | www亚洲精品 | 国产视频福利一区 | 中文在线一区二区 | 国产午夜亚洲精品不卡 | 国产视频不卡一区 | 视频一区二区中文字幕 | 在线观看精品 | 成人在线观看免费 | 成人欧美在线 | 国产精品成人久久久久a级 久久蜜桃av一区二区天堂 | 97免费视频在线观看 | 免费观看毛片 |