亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Python 通過流將數據從 S3 傳輸到 FTP 服務器

使用 Python 通過流將數據從 S3 傳輸到 FTP 服務器

慕沐林林 2023-06-13 17:02:00
使用 Python,我想將匹配模式的文件sample1從 AWS S3 直接復制到 FTP 服務器,而無需下載到本地臨時位置。我嘗試了以下操作:import s3fsfrom ftplib import FTP_TLSs3 = s3fs.S3FileSystem(anon=False)pattern = 'sample1'rest = [i for i in list if pattern in i]restftp = FTP_TLS("ftp.test.com")ftp.login(user ='myUser', passwd = 'PassWrd')ftp.cwd("box_dest")for f in rest:    print(f)    with open(f, 'r') as fu:        ftp.storbinary('STOR ' + f, fu)我越來越:[u'test-bucket/abc/test/sample1.csv']test-bucket/abc/test/sample1.csvTraceback (most recent call last):  File "<stdin>", line 3, in <module>IOError: [Errno 2] No such file or directory: u'test-bucket/abc/test/sample1.csv'關于如何實現這一目標的任何建議?謝謝!
查看完整描述

1 回答

?
紅顏莎娜

TA貢獻1842條經驗 獲得超13個贊

要從 S3 讀取文件,您需要使用S3FileSystem.open,而不是os.open.


在指定目標 FTP 路徑時,您只需要從原始 S3 路徑中提取一個文件名。posixpath.basename應該做。


for f in rest:

    print(f)

    with s3.open(f, 'r') as fu:

        ftp.storbinary('STOR ' + posixpath.basename(f), fu)


查看完整回答
反對 回復 2023-06-13
  • 1 回答
  • 0 關注
  • 186 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號