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

問題描述

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

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)一起使用時,當(dāng)然不提供 EOL.

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

所以,對于初學(xué)者來說,我想出了這段對我來說看起來不錯"的代碼,但由于我是一個相對的 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 腳本從大型機(jī)下載 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:“浮動對象不可下標(biāo))
主站蜘蛛池模板: 亚洲综合视频 | 伊人艹| 毛片综合 | 日韩福利在线观看 | 日本在线视频不卡 | 亚洲国产一区二区三区在线观看 | 亚洲国产视频一区二区 | 国产免费一区二区 | 国产高清在线精品一区二区三区 | 亚洲精品视频一区 | 日韩精品一区二区三区中文在线 | 日本一区二区在线视频 | 一级免费毛片 | 色888www视频在线观看 | www.天天操 | av电影一区 | 亚洲天堂精品一区 | 亚洲成av人片在线观看无码 | av中文天堂 | 久久综合伊人一区二区三 | 欧美情趣视频 | 色综合天天天天做夜夜夜夜做 | 国产不卡一区在线观看 | 一区二区福利视频 | 夜夜爽99久久国产综合精品女不卡 | a级在线免费观看 | 999视频| 精品欧美一区二区三区精品久久 | 一区二区三区播放 | 欧美精品久久久久 | 午夜a区| 国产一区二区三区精品久久久 | 日韩精品亚洲专区在线观看 | 日本精品一区二区三区视频 | 日日天天 | www操操| 久久丁香| 羞羞的视频免费在线观看 | 亚洲性视频网站 | 国产在线观看一区 | 91久久久久久久久久久久久 |