Update by natay on Mon May 14 00:01:48 EDT 2018 from natay
-import logging
-import glob
-
from django.core.management.base import BaseCommand
from ftplib import FTP
@@ -10,10 +7,9 @@ from biostar.settings import *
CURRENT_FILE = os.path.abspath(__file__)
-logger = logging.getLogger("engine")
class Command(BaseCommand):
- help = "Add users"
+ help = "A Test FTP client used to test the server."
def handle(self, *args, **options):
@@ -26,22 +22,28 @@ class Command(BaseCommand):
# Initial list of projects
projects = list(ftp.nlst())
- print('\n'.join(projects))
- print("-----")
+ print('\n'.join(projects) + "\n-----")
project_name = "Test FTP project"
# Create a new project at the root directory
- print(ftp.mkd(project_name))
+ ftp.mkd(project_name)
# Check to see the project has been created
project_created = project_name in list(ftp.nlst())
print(f"Project creation and upload successful: {project_created}\n-----")
# Switch the cwd to the /data directory of newly created project.
- # Creating a dir here will create a Data object in the project.
ftp.cwd(os.path.join(project_name, "data"))
- # Point to the directory we want to upload
+ # Creating a dir here will create a Data object in the project.
+ ftp.mkd("Test FTP Data")
+ ftp.cwd("Test FTP Data")
+
+ # Make another directory
+ ftp.mkd("store")
+ ftp.cwd("store")
+
+ # Point to the file we want to upload
file = open(CURRENT_FILE , 'rb')
fname = os.path.basename(CURRENT_FILE)
cmd = f"STOR {fname}"
@@ -52,7 +54,5 @@ class Command(BaseCommand):
# Check to see Data object has been created in database
# and the dir is in the ftp server.
data_created = fname in list(ftp.nlst())
- print(f"Data object and files created: {data_created}. Look in {project_name}")
+ print(f"Data object and files created: {data_created}. Look in {project_name}\n-----")
- # Test download of entire test project we just uploaded
- ftp.cwd("/")
