Create and return a logged in FTP object.
    :return:
358553
def login_hq(host, user, passwd, path='', acct='', port=21, timeout=5):
    
    ftp = ftplib.FTP()
    ftp.connect(host=host, port=port, timeout=timeout)
    ftp.login(user=user, passwd=passwd, acct=acct)
    ftp.cwd(path)
    logger.debug('Login to %s successful.' % host)
    return ftp
518562
def _open_ftp(self):
        # type: () -> FTP
        
        _ftp = FTP()
        _ftp.set_debuglevel(0)
        with ftp_errors(self):
            _ftp.connect(self.host, self.port, self.timeout)
            _ftp.login(self.user, self.passwd, self.acct)
            self._features = {}
            try:
                feat_response = _decode(_ftp.sendcmd("FEAT"), "latin-1")
            except error_perm:  # pragma: no cover
                self.encoding = "latin-1"
            else:
                self._features = self._parse_features(feat_response)
                self.encoding = "utf-8" if "UTF8" in self._features else "latin-1"
                if not PY2:
                    _ftp.file = _ftp.sock.makefile(  # type: ignore
                        "r", encoding=self.encoding
                    )
        _ftp.encoding = self.encoding
        self._welcome = _ftp.welcome
        return _ftp
579636
def create(self, filename, filedata):
        """"""
        attributes = {'filename': filename,
                      'source': filedata}
        return self.transport.POST(url='/file/v2/', body=attributes, type='multipart/form-data')
1296963
def make_sftp(self):
        """"""
        transport = self.client.get_transport()
        transport.open_session()
        return paramiko.SFTPClient.from_transport(transport)
337459
def _log_in(self):
        '''
        '''
        username = self._request.url_info.username or self._request.username or 'anonymous'
        password = self._request.url_info.password or self._request.password or '-wpull@'

        cached_login = self._login_table.get(self._control_connection)

        if cached_login and cached_login == (username, password):
            _logger.debug('Reusing existing login.')
            return

        try:
            yield from self._commander.login(username, password)
        except FTPServerError as error:
            raise AuthenticationError('Login error: {}'.format(error)) \
                from error

        self._login_table[self._control_connection] = (username, password)
624188
def connectionMade(self):
        
        cmd = stomper.connect(self.username, self.password)
        self.transport.write(cmd)
731832
def create_socket():
    
    sock = socket.socket(PF_CAN, socket.SOCK_RAW, CAN_RAW)

    log.info('Created a socket')

    return sock
921732
def ftp_get(fin_src, fout):
    """"""
    assert fin_src[:6] == 'ftp://', fin_src
    dir_full, fin_ftp = os.path.split(fin_src[6:])
    pt0 = dir_full.find('/')
    assert pt0 != -1, pt0
    ftphost = dir_full[:pt0]
    chg_dir = dir_full[pt0+1:]
    print('FTP RETR {HOST} {DIR} {SRC} -> {DST}'.format(
        HOST=ftphost, DIR=chg_dir, SRC=fin_ftp, DST=fout))
    ftp = FTP(ftphost)  # connect to host, default port      ftp.ncbi.nlm.nih.gov
    ftp.login()         # user anonymous, passwd anonymous@
    ftp.cwd(chg_dir)    # change into "debian" directory     gene/DATA
    cmd = 'RETR {F}'.format(F=fin_ftp)   #                   gene2go.gz
    ftp.retrbinary(cmd, open(fout, 'wb').write)  #           /usr/home/gene2go.gz
    ftp.quit()
1369430
def create(self):
        
        fdint = os.open(self.path, (os.O_EXCL |
                                    os.O_CREAT |
                                    os.O_RDWR))

        # XXX TODO: 'name' attribute of returned files is not mutable or
        # settable via fdopen, so this file is slighly less functional than the
        # one returned from 'open' by default.  send a patch to Python...

        return os.fdopen(fdint, 'w+b')
616748
def session(self) -> BaseFileWriterSession:
        ''''''
        return self.session_class(
            self._path_namer,
            self._file_continuing,
            self._headers_included,
            self._local_timestamping,
            self._adjust_extension,
            self._content_disposition,
            self._trust_server_names,
        )
1224988
def _get_data_raw(self):
        
        # Import need to be here so we can monkeypatch urlopen for testing and avoid
        # downloading live data for testing
        try:
            from urllib.request import urlopen
        except ImportError:
            from urllib2 import urlopen

        with closing(urlopen(self.ftpsite + self.site_id + self.suffix + '.zip')) as url:
            f = ZipFile(BytesIO(url.read()), 'r').open(self.site_id + self.suffix)

        lines = [line.decode('utf-8') for line in f.readlines()]

        body, header, dates_long, dates = self._select_date_range(lines)

        return body, header, dates_long, dates
464897
def open_readable(self, name):
        
        # print("FTP open_readable({})".format(name))
        assert compat.is_native(name)
        out = SpooledTemporaryFile(max_size=self.MAX_SPOOL_MEM, mode="w+b")
        self.ftp.retrbinary(
            "RETR {}".format(name), out.write, FtpTarget.DEFAULT_BLOCKSIZE
        )
        out.seek(0)
        return out
1353157
def create_files(filedef, cleanup=True):
    
    cwd = os.getcwd()
    tmpdir = tempfile.mkdtemp()
    try:
        Filemaker(tmpdir, filedef)
        if not cleanup:  # pragma: nocover
            pass
            # print("TMPDIR =", tmpdir)
        os.chdir(tmpdir)
        yield tmpdir
    finally:
        os.chdir(cwd)
        if cleanup:  # pragma: nocover
            shutil.rmtree(tmpdir, ignore_errors=True)
746579
def _create(self, **kwargs):
        '''
        '''

        try:
            return super(Service, self)._create(**kwargs)
        except HTTPError as ex:
            if "The configuration was updated successfully but could not be " \
                    "retrieved" not in ex.response.text:
                raise

            # BIG-IP® will create in Common partition if none is given.
            # In order to create the uri properly in this class's load,
            # drop in Common as the partition in kwargs.
            if 'partition' not in kwargs:
                kwargs['partition'] = 'Common'
            # Pop all but the necessary load kwargs from the kwargs given to
            # create. Otherwise, load may fail.
            kwargs_copy = kwargs.copy()
            for key in kwargs_copy:
                if key not in self._meta_data['required_load_parameters']:
                    kwargs.pop(key)
            # If response was created successfully, do a local_update.
            # If not, call to overridden _load method via load
            return self.load(**kwargs)
1056901
def init_log(log_file):
    
    #Create the log file
    log = None
    try:
        log = open(log_file, 'a')

        #Change the output to both the windows and log file
        #original = sys.stdout
        sys.stdout = Tee(sys.stdout, log)
    except:
        pass
    return log
946522
def create_client_for_file(self, filename, is_cython=False):
        """"""
        # Create client
        self.create_new_client(filename=filename, is_cython=is_cython)

        # Don't increase the count of master clients
        self.master_clients -= 1

        # Rename client tab with filename
        client = self.get_current_client()
        client.allow_rename = False
        tab_text = self.disambiguate_fname(filename)
        self.rename_client_tab(client, tab_text)
287285
def get_new_client(self, public=True):
        
        return self._get_client(public=public, cached=False)