Beispiel #1
0
def submit_records_via_ftp(filename, location=""):
    """Submits given file to FTP server as defined.

    The FTP server uploaded to is controlled with the config variables:

    CFG_FTP_AUTHENTICATION_FILE (netrc_file)
    CFG_FTP_SERVER

    @param filename: file to upload
    @type filename: str

    @param location: location on FTP server. Defaults to root.
    @type location: str
    """
    from invenio.config import (CFG_FTP_SERVER,
                                CFG_FTP_AUTHENTICATION_FILE,)

    try:
        ftp = FtpHandler(CFG_FTP_SERVER, netrc_file=CFG_FTP_AUTHENTICATION_FILE)
        ftp.upload(filename, location)
        ftp.close()
        write_message("%s successfully uploaded to FTP server" % filename)
    except Exception as e:
        write_message("Failed to upload %s to FTP server: %s\n%s"
                      % (filename, str(e), traceback.format_exc()))
Beispiel #2
0
def ftp_list_files(server_folder, target_folder, **serverinfo):
    """List files from given FTP's server folder to target folder."""
    ftp = FtpHandler(**serverinfo)
    ftp.cd(server_folder)
    missing_files = []
    all_files = []
    for filename in ftp.ls()[0]:
        destination_file = os.path.join(target_folder, filename)
        source_file = os.path.join(server_folder, filename)
        if not os.path.exists(destination_file):
            missing_files.append(source_file)
        all_files.append(source_file)
    return all_files, missing_files
Beispiel #3
0
    def connect(self):
        """Logs into the specified ftp server and returns connector."""
        for tryed_connection_count in range(CFG_FTP_CONNECTION_ATTEMPTS):
            try:
                self.ftp = FtpHandler(self.config.SPRINGER.URL,
                                      self.config.SPRINGER.LOGIN,
                                      self.config.SPRINGER.PASSWORD)
                self.logger.debug(("Successful connection to "
                                   "the Springer server"))
                return
            except socket_timeout_exception as err:
                self.logger.error(
                    ('Failed to connect %d of %d times. '
                     'Will sleep for %d seconds and try again.') %
                    (tryed_connection_count + 1, CFG_FTP_CONNECTION_ATTEMPTS,
                     CFG_FTP_TIMEOUT_SLEEP_DURATION))
                time.sleep(CFG_FTP_TIMEOUT_SLEEP_DURATION)
            except Exception as err:
                self.logger.error(("Failed to connect to the "
                                   "Springer server. %s") % (err, ))
                break

        raise LoginException(err)