![](/img/trans.png)
[英]Problem writing data to S3 with Kinesis Firehose Delivery Stream from Kinesis Data Stream source
[英]Transfer the data from S3 to FTP server via stream using Python
使用 Python,我想將與模式sample1
匹配的文件從 AWS S3 直接復制到 FTP 服務器,而無需下載到本地臨時位置。 我嘗試了以下操作:
import s3fs
from ftplib import FTP_TLS
s3 = s3fs.S3FileSystem(anon=False)
pattern = 'sample1'
rest = [i for i in list if pattern in i]
rest
ftp = 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.csv
Traceback (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'
關於如何實現這一目標的任何建議? 謝謝!
要從 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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.