'STORE (STOR)
This command causes the server-DTP to accept the data
transferred via the data connection and to store the data as
a file at the server site.  If the file specified in the
pathname exists at the server site, then its contents shall
be replaced by the data being transferred.  A new file is
created at the server site if the file specified in the
pathname does not already exist.'

def ftp_STOR(self, path):

    if (self.dtpInstance is None):
        raise BadCmdSequenceError('PORT    or    PASV    required    before    STOR')
    try:
        newsegs = toSegments(self.workingDirectory, path)
    except InvalidPath:
        return defer.fail(FileNotFoundError(path))
    self.setTimeout(None)
    def enableTimeout(result):
        self.setTimeout(self.factory.timeOut)
        return result
    def cbOpened(file):
        '\n                                                File    was    open    for    reading.    Launch    the    data    transfer    channel    via\n                                                the    file    consumer.\n                                                '
        d = file.receive()
        d.addCallback(cbConsumer)
        d.addCallback((lambda ignored: file.close()))
        d.addCallbacks(cbSent, ebSent)
        return d
    def ebOpened(err):
        '\n                                                Called    when    failed    to    open    the    file    for    reading.\n\n                                                For    known    errors,    return    the    FTP    error    code.\n                                                For    all    other,    return    a    file    not    found    error.\n                                                '
        if isinstance(err.value, FTPCmdError):
            return (err.value.errorCode, '/'.join(newsegs))
        log.err(err, 'Unexpected    error    received    while    opening    file:')
        return (FILE_NOT_FOUND, '/'.join(newsegs))
    def cbConsumer(cons):
        '\n                                                Called    after    the    file    was    opended    for    reading.\n\n                                                Prepare    the    data    transfer    channel    and    send    the    response\n                                                to    the    command    channel.\n                                                '
        if (not self.binary):
            cons = ASCIIConsumerWrapper(cons)
        d = self.dtpInstance.registerConsumer(cons)
        if self.dtpInstance.isConnected:
            self.reply(DATA_CNX_ALREADY_OPEN_START_XFR)
        else:
            self.reply(FILE_STATUS_OK_OPEN_DATA_CNX)
        return d
    def cbSent(result):
        '\n                                                Called    from    data    transport    when    tranfer    is    done.\n                                                '
        return (TXFR_COMPLETE_OK,)
    def ebSent(err):
        '\n                                                Called    from    data    transport    when    there    are    errors    during    the\n                                                transfer.\n                                                '
        log.err(err, 'Unexpected    error    received    during    transfer:')
        if err.check(FTPCmdError):
            return err
        return (CNX_CLOSED_TXFR_ABORTED,)
    d = self.shell.openForWriting(newsegs)
    d.addCallbacks(cbOpened, ebOpened)
    d.addBoth(enableTimeout)
    return d
