I am trying hard to implement this function:
change the directories if they are present in FTP and if not, create them and change directories to it.
def directory_exists(self, directory_name):
        if directory_name in ftp.nlst():
            self.change_directory(directory_name)
        else:
            self.make_directory(directory_name) and self.change_directory(directory_name)
Function calls:
def make_directory(self, directory):
        if ftp.mkd(directory):
            self.log_message("Directory {0} created successfully".format(directory))
            return True
        else:
            self.log_message("Failed creating directory")
            return False
def change_directory(self, directory):
        if ftp.cwd(directory):
            self.log_message("Current Directory is now {0}".format(ftp.pwd()))
        else:
            self.log_message("Can't change Directory")
This code currently works if any new directory is given as the parameter and if the existing directory is given, this traceback comes.
Traceback (most recent call last):
  File "C:/Users/Ajay/PycharmProjects/database/config.py", line 17, in <module>
    ftp_obj.directory_exists(directory)
  File "C:\Users\Ajay\PycharmProjects\database\ftp.py", line 51, in directory_exists
    self.make_directory(directory_name) and self.change_directory(directory_name)
  File "C:\Users\Ajay\PycharmProjects\database\ftp.py", line 34, in make_directory
    if ftp.mkd(directory):
  File "C:\Python27\lib\ftplib.py", line 568, in mkd
    resp = self.sendcmd('MKD ' + dirname)
  File "C:\Python27\lib\ftplib.py", line 244, in sendcmd
    return self.getresp()
  File "C:\Python27\lib\ftplib.py", line 219, in getresp
    raise error_perm, resp
ftplib.error_perm: 550 Can't create directory: File exists
My Code Function call logic:
directory = '/new'
ftp_obj.directory_exists(directory)

andworks...ftp.nlst()returns a list that is in the same format asdirectory_name? For instance might one of them be an absolute path?