diff --git a/services/ftp/config.json b/services/ftp/config.json index e675943d..42d93a20 100644 --- a/services/ftp/config.json +++ b/services/ftp/config.json @@ -20,5 +20,13 @@ "label": "FTP Server", "description": "An empty FTP server.", "conflicts_with": [] - } + }, + "parameters": [ + { + "type": "file", + "value": "ftp_content", + "label": "FTP Content - Optional path or a base64 encoded string of a zip file containing the content for the ftp service", + "required": false + } + ] } diff --git a/services/ftp/ftp_service.py b/services/ftp/ftp_service.py index 1aa0f867..1b6a26a1 100644 --- a/services/ftp/ftp_service.py +++ b/services/ftp/ftp_service.py @@ -6,6 +6,12 @@ import os import shutil import ftplib +import base64 +import zipfile +try: + from StringIO import StringIO +except ImportError: + from io import StringIO from pyftpdlib.handlers import FTPHandler from pyftpdlib.servers import FTPServer @@ -167,6 +173,14 @@ def __init__(self, *args, **kwargs): def prepare_temp_dir(self): """Create a temp dir.""" self.temp_dir = tempfile.mkdtemp() + content = self.service_args.get("ftp_content") + if content: + if os.path.exists(content): + file_obj = open(content, "r") + else: + file_obj = StringIO(base64.b64decode(content)) + z = zipfile.ZipFile(file_obj, "r") + z.extractall(self.temp_dir) def delete_temp_dir(self): """Delete the temp dir that we created."""