FTP for Google Storage

Some files are uploaded daily to the FTP server, and I need these files in Google Cloud Storage. I don’t want users to upload files to install any additional software, and just let them continue to use their FTP client. Is there a way to use GCS as an FTP server? If not, how can I create a task that periodically collects files from an FTP address and puts them in GCS? In other words: what is the best and easiest way to do this?

+4
source share
3 answers

I have successfully configured FTP proxy for GCS using gcsfs in VM in Google Compute (mentioned by jkff in the comment to my question), with these instructions: http://ilyapimenov.com/blog/2015/01/19/ftp-proxy- to-gcs.html

Some changes are required:

Some possible problems:

  • If you can access the FTP server using a local IP address but not a remote ip, it is possible because you have not configured firewall rules
  • ftp-, , , , write_enable = YES
  • , /mnt, -, , , , gcsfs_config .

, ftp- , "".

+1

FTP-, GCS, , pyftpdlib

, GCS

import os
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
from pyftpdlib.authorizers import DummyAuthorizer
from google.cloud import storage

class MyHandler:
    def on_file_received(self, file):
        storage_client = storage.Client()
        bucket = storage_client.get_bucket('your_gcs_bucket')
        blob = bucket.blob(file[5:]) # strip leading /tmp/
        blob.upload_from_filename(file)
        os.remove(file)
    def on_... # implement other events

def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('user', 'password', homedir='/tmp', perm='elradfmw')

    handler = MyHandler
    handler.authorizer = authorizer
    handler.masquerade_address = add.your.public.ip
    handler.passive_ports = range(60000, 60999)

    server = FTPServer(("127.0.0.1", 21), handler)
    server.serve_forever()

if __name__ == "__main__":
    main()

Google Container Engine ( FTP), Compute Engine. 21 60000 - 60999 .

, python my_ftp_server.py - 21, root.

+6

cron rsync FTP- Google, gsutil rsync rclone.

FTP-, FTP- (Linux, Windows)

+2
source

Source: https://habr.com/ru/post/1675113/


All Articles