def _transmit(self, queue_item, subscriber): config = queue_item.get("destination", {}).get("config", {}) try: with ftp_connect(config) as ftp: if config.get("push_associated", False): # Set the working directory for the associated files if "associated_path" in config and config.get( "associated_path"): ftp.cwd("/" + config.get("associated_path", "").lstrip("/")) item = self._get_published_item(queue_item) if item: self._copy_published_media_files(item, ftp) # If the directory was changed to push associated files change it back if "associated_path" in config and config.get( "associated_path"): ftp.cwd("/" + config.get("path").lstrip("/")) filename = get_publish_service().get_filename(queue_item) b = BytesIO( queue_item.get( "encoded_item", queue_item.get("formatted_item").encode("UTF-8"))) ftp.storbinary("STOR " + filename, b) except PublishFtpError: raise except Exception as ex: raise PublishFtpError.ftpError(ex, queue_item.get("destination"))
def _transmit(self, queue_item, subscriber): config = queue_item.get('destination', {}).get('config', {}) try: with ftp_connect(config) as ftp: if config.get('push_associated', False): # Set the working directory for the associated files if 'associated_path' in config and config.get('associated_path'): ftp.cwd('/' + config.get('associated_path', '').lstrip('/')) item = self._get_published_item(queue_item) if item: self._copy_published_media_files(item, ftp) # If the directory was changed to push associated files change it back if 'associated_path' in config and config.get('associated_path'): ftp.cwd('/' + config.get('path').lstrip('/')) filename = get_publish_service().get_filename(queue_item) b = BytesIO(queue_item.get('encoded_item', queue_item.get('formatted_item').encode('UTF-8'))) ftp.storbinary('STOR ' + filename, b) except PublishFtpError: raise except Exception as ex: raise PublishFtpError.ftpError(ex, config)
def _transmit(self, queue_item, subscriber): config = queue_item.get('destination', {}).get('config', {}) try: with ftp_connect(config) as ftp: filename = PublishService.get_filename(queue_item) b = BytesIO(queue_item['encoded_item']) ftp.storbinary("STOR " + filename, b) except PublishFtpError: raise except Exception as ex: raise PublishFtpError.ftpError(ex, config)
def _transmit(self, queue_item, subscriber): config = queue_item.get('destination', {}).get('config', {}) try: with ftplib.FTP(config.get('host')) as ftp: ftp.login(config.get('username'), config.get('password')) ftp.cwd(config.get('path', '').lstrip('/')) ftp.set_pasv(config.get('passive', False)) filename = '{}.{}'.format(queue_item['item_id'].replace(':', '-'), get_file_extension(queue_item)) b = BytesIO(bytes(queue_item['formatted_item'], 'UTF-8')) ftp.storbinary("STOR " + filename, b) except PublishFtpError: raise except Exception as ex: raise PublishFtpError.ftpError(ex, config)
def _transmit(self, formatted_item, subscriber, destination): config = destination.get('config', {}) try: with ftplib.FTP(config.get('host')) as ftp: ftp.login(config.get('username'), config.get('password')) ftp.cwd(config.get('path', '').lstrip('/')) ftp.set_pasv(config.get('passive', False)) filename = '{}.{}'.format(formatted_item['item_id'].replace(':', '-'), get_file_extension(formatted_item)) b = BytesIO(bytes(formatted_item['formatted_item'], 'UTF-8')) ftp.storbinary("STOR " + filename, b) except PublishFtpError: raise except Exception as ex: raise PublishFtpError.ftpError(ex, destination)
# -*- coding: utf-8; -*- # # This file is part of Superdesk. # # Copyright 2013, 2014 Sourcefabric z.u. and contributors. # # For the full copyright and license information, please see the # AUTHORS and LICENSE files distributed with this source code, or # at https://www.sourcefabric.org/superdesk/license from superdesk.ftp import ftp_connect from superdesk.publish import register_transmitter from io import BytesIO from superdesk.publish.publish_service import PublishService from superdesk.errors import PublishFtpError errors = [PublishFtpError.ftpError().get_error_description()] try: from urllib.parse import urlparse except ImportError: from urlparse import urlparse class FTPPublishService(PublishService): """FTP Publish Service.""" def config_from_url(self, url): """Parse given url into ftp config. Used for tests. :param url: url in form `ftp://username:password@host:port/dir` """
# -*- coding: utf-8; -*- # # This file is part of Superdesk. # # Copyright 2013, 2014 Sourcefabric z.u. and contributors. # # For the full copyright and license information, please see the # AUTHORS and LICENSE files distributed with this source code, or # at https://www.sourcefabric.org/superdesk/license from superdesk.ftp import ftp_connect from superdesk.publish import register_transmitter from io import BytesIO from superdesk.publish.publish_service import PublishService from superdesk.errors import PublishFtpError errors = [PublishFtpError.ftpError().get_error_description()] try: from urllib.parse import urlparse except ImportError: from urlparse import urlparse class FTPPublishService(PublishService): """FTP Publish Service.""" def config_from_url(self, url): """Parse given url into ftp config. Used for tests. :param url: url in form `ftp://username:password@host:port/dir` """ url_parts = urlparse(url)