Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support content for the ftp plugin #109

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion services/ftp/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,13 @@
"label": "FTP Server",
"description": "An empty FTP server.",
"conflicts_with": []
}
},
"parameters": [
{
"type": "file",
"value": "ftp_content",
"label": "FTP Content - optional zip file containing the content for the ftp service",
dekelb marked this conversation as resolved.
Show resolved Hide resolved
"required": false
}
]
}
14 changes: 14 additions & 0 deletions services/ftp/ftp_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down