Beispiel #1
0
        def do_download(ftp_conn):
            """do download with connected ftp connection."""
            save_path = os.path.join(path, self.name)

            if self.is_dir:
                if not os.path.isdir(save_path):
                    os.makedirs(save_path)

                children = self.poll()
                for child in children:
                    with children[child] as af:
                        # download child with same ftp connection
                        af._download(save_path, ftp)
            else:
                try:
                    with open(save_path, "w+") as fd:
                        ftp_conn.retrbinary(u"RETR %s" % self.path, fd.write)
                except OSError as err:
                    raise exception.FtpError(err)
                except IOError as err:
                    raise exception.FtpError(err)
Beispiel #2
0
    def connect(self):
        """connect to ftp, return ftp connection."""
        if self.ftp is None:
            jenkins = self.get_jenkins_obj()
            if jenkins.ftp_host is None:
                raise exception.FtpError("cannot connect to ftp server before enable ftp")

            self.ftp = ftplib.FTP()
            try:
                self.ftp.connect(jenkins.ftp_host, jenkins.ftp_port)
                self.ftp.login(jenkins.ftp_username, jenkins.ftp_password)
            except ftplib.error_perm as err:
                self.ftp.close()
                self.ftp = None
                raise exception.FtpError(err)
            except socket.error as err:
                self.ftp.close()
                self.ftp = None
                raise exception.FtpError(err)

        return self.ftp
Beispiel #3
0
    def url(self):
        """get ftp artifact url."""
        jenkins = self.get_jenkins_obj()
        if jenkins.ftp_host is None:
            raise exception.FtpError("cannot get ftp url before enable ftp")

        netloc = []
        if jenkins.ftp_username:
            netloc.append(jenkins.ftp_username)
            if jenkins.ftp_password:
                netloc.append(":")
                netloc.append(jenkins.ftp_password)
            netloc.append("@")

        netloc.append(jenkins.ftp_host)
        if jenkins.ftp_port:
            netloc.append(":")
            netloc.append(str(jenkins.ftp_port))

        netloc = "".join(netloc)
        return urlparse.urlunparse(("ftp", netloc, self.path, "", "", ""))