久久久久久久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 作為回調一起使用時,當然不提供 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 具有固定的記錄結構,而不是依賴行結尾作為記錄分隔符.但是,z/os FTP 服務器在以文本模式傳輸時,會提供記錄結尾,而 retrlines() 會去掉這些結尾.

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.

結束更新:

這是我修改后的解決方案,它將成為持續開發的基礎(例如,刪除內置密碼):

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 遞歸下載數據集時遇到了這個問題.多年來,我一直在使用簡單的 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)

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

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

相關文檔推薦

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:“浮動對象不可下標)
主站蜘蛛池模板: 国产精品美女 | 日一日操一操 | 亚洲综合三区 | 久久精品久久久久久久 | 黄色av大片 | 九九影视理伦片 | 亚洲天堂网在线观看 | 糖心vlog精品一区二区 | 波多野结衣一区二区三区 | 蜜桃精品一区二区三区 | 日本三级大片 | 真实人妻互换毛片视频 | 糖心vlog精品一区二区 | 超碰免费人人 | 国产一区二区在线看 | 精品国产一区二区三区四区 | 日韩欧美精品 | 国产九九九 | 日韩免费大片 | 天堂a√ | 五月婷婷视频 | 国产欧美精品一区二区色综合 | 亚洲福利片 | 成人免费视频视频 | 亚洲精品欧美 | 午夜免费av | 偷拍一区二区三区 | 伊人网综合 | 一级黄片毛片 | 免费看黄色aaaaaa 片 | 中国少妇xxxxhd做受 | 精品亚洲一区二区 | 欧美久久久久久 | 欧美性猛交xxxx乱大交退制版 | 亚洲欧洲在线观看 | 久久狠狠干 | 欧美一区二区三区的 | 亚洲精品小视频 | 黄色免费在线视频 | 日韩欧美中文在线 | 欧美日韩在线一区二区 |