所有oftps3
在aws s3前面使用ftp,使用asyncio,和aiohttp。只支持FTP协议的一个子集,使用隐式TLS和PASV模式;否则连接将失败。
安装pip install aioftps3
SSL密钥和证书必须分别存在$HOME/ssl.key和$HOME/ssl.crt。要创建自签名证书,可以使用openssl。openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 -subj /CN=selfsigned \
-keyout $HOME/ssl.key \
-out $HOME/ssl.crt
运行python -m aioftps3.server_main
配置
配置是通过环境变量进行的VaraiableDescriptionExample^{}How requests to AWS are authenticated. Can be ^{} or ^{}. If ^{} it is expected that the server runs in an ECS container.^{}
^{}The ID of the AWS access key, if ^{} is ^{}.ommitted
^{}The secret part of the AWS access key, if ^{} is ^{}ommitted
^{}The region of the S3 bucket that stores the files.^{}
^{}The hostname used to communicate with S3.^{}
^{}The name of the bucket files are stored in.^{}
^{}The suffix of the keys created in order to simulate a directory. Must start with a forward slash, but does not need to be longer.^{}
^{}For ^{} any integer, the username of an FTP user that can login.^{}
^{}For ^{} any integer, the hash, as generated by create_password.py, of the password of an FTP user that can login, using the salt in ^{}ommitted
^{}See ^{}ommitted
^{}The port that the server listens on for command connections.^{}
^{}The first data port in the range for PASV mode data transfers.^{}
^{}The number of ports used after ^{}.^{}
^{}For ^{} any integer, a CIDR range used to match the IP of incoming command connections. If a match is found, the IP of the corresponding domain or IP address in ^{} is returned to the client in response to PASV mode requests. Some clients will respond to ^{} being ^{} by making PASV mode data connections to the same IP as the original command connection, but not all.^{}
^{}See ^{}.^{}
^{}The port the server listens on for healthcheck requests, such as from an AWS network load balancer.^{}
高级用法
aioftps3.server_main中的代码满足一个非常特殊的用例,这可能对大多数人都没有用处。但是,大部分代码可以用于其他情况:您必须使用函数aioftps3.server.on_client_connect和aioftps3.server_socket.server编写自己的aioftps3.server_main-equivalent。例如,您可以将凭据以适当的哈希值以不同的方式存储在数据库中。
对凭据进行不同的哈希处理。
允许/拒绝基于某些条件的PASV模式数据连接。
有关如何使用这些函数的信息,请参见aioftps3.server_main的源代码。
创建密码和saltpython ./create_password.py
运行测试
必须创建证书,并且必须启动本地模拟s3的minio./certificates-create.sh && ./minio-start.sh
然后自己运行测试。./tests.sh
功能/设计/限制可以上传大于2g的文件:在引擎盖下使用multipart upload。
在上传文件到s3之前,不会将上传文件存储在内存中:即,它实际上是流式上传。然而,它并不是完全流式的:多部分上传的每个部分在传输到s3之前都存储在内存中,以便能够散列其内容并确定其长度。
对于上传文件,哈希是随着数据的到来而递增计算的,以便在上传到s3之前不阻塞事件循环。
尽可能少的依赖是合理的:aiohttp及其依赖。boto 3未使用。
如果上传到服务器的速度比上传到s3的速度快,则可能表现不好。
有一些锁来处理同时操作的相同文件。然而。。。
在本地构建和运行docker build -t ftps-s3 . &&\
docker run --rm -p 8021-8042:8021-8042 \
-e AWS_AUTH_MECHANISM=secret_access_key \
-e AWS_ACCESS_KEY_ID=ommitted \
-e AWS_SECRET_ACCESS_KEY=ommitted \
-e AWS_S3_BUCKET_REGION=eu-west-1 \
-e AWS_S3_BUCKET_HOST=s3-eu-west-1.amazonaws.com \
-e AWS_S3_BUCKET_NAME=my-bucket-name \
-e AWS_S3_BUCKET_DIR_SUFFIX=/ \
-e FTP_USERS__1__LOGIN=user \
-e FTP_USERS__1__PASSWORD_HASHED=ommitted \
-e FTP_USERS__1__PASSWORD_SALT=ommitted \
-e FTP_COMMAND_PORT=8021\
-e FTP_DATA_PORTS_FIRST=4001\
-e FTP_DATA_PORTS_COUNT=2\
-e FTP_DATA_CIDR_TO_DOMAINS__1__CIDR=0.0.0.0/0 \
-e FTP_DATA_CIDR_TO_DOMAINS__1__DOMAIN=0.0.0.0 \
-e HEALTHCHECK_PORT=8022
ftps-s3
建造并推进码头docker build -t ftps-s3 . &&\
docker tag ftps-s3:latest quay.io/uktrade/ftps-s3:latest &&\
docker push quay.io/uktrade/ftps-s3:latest
建立并将healthcheck应用程序推送到码头docker build -t ftps-s3-healthcheck . -f Dockerfile-healthcheck &&\
docker tag ftps-s3-healthcheck:latest quay.io/uktrade/ftps-s3-healthcheck:latest &&\
docker push quay.io/uktrade/ftps-s3-healthcheck:latest
建造并推动Minio,用于测试,以使其达到码头docker build -t ftps-s3-minio . -f Dockerfile-minio &&\
docker tag ftps-s3-minio:latest quay.io/uktrade/ftps-s3-minio:latest &&\
docker push quay.io/uktrade/ftps-s3-minio:latest
欢迎加入QQ群-->: 979659372
推荐PyPI第三方库