def ftp_connect(self, host, user='anonymous', password='anonymous@', port=21, timeout=30, connId='default'):
        """
        Constructs FTP object, opens a connection and login.
        Call this function before any other (otherwise raises exception).
        Returns server output.
        Parameters:
            - host - server host address
            - user(optional) - FTP user name. If not given, 'anonymous' is used.
            - password(optional) - FTP password. If not given, 'anonymous@' is used.
            - port(optional) - TCP port. By default 21.
            - timeout(optional) - timeout in seconds. By default 30.
            - connId(optional) - connection identifier. By default equals 'default'
        Examples:
        | ftp connect | 192.168.1.10 | mylogin | mypassword |  |  |
        | ftp connect | 192.168.1.10 |  |  |  |  |
        | ftp connect | 192.168.1.10 | mylogin | mypassword | connId=secondConn |  |
        | ftp connect | 192.168.1.10 | mylogin | mypassword | 29 | 20 |
        | ftp connect | 192.168.1.10 | mylogin | mypassword | 29 |  |
        | ftp connect | 192.168.1.10 | mylogin | mypassword | timeout=20 |  |
        | ftp connect | 192.168.1.10 | port=29 | timeout=20 |  |  |
        """
        if connId in self.ftpList:
            errMsg = "Connection with ID %s already exist. It should be deleted before this step." % connId
            raise FtpLibraryError(errMsg)
        else:
            newFtp = None
            outputMsg = ""
            try:
                timeout = int(timeout)
                port = int(port)
                newFtp = ftplib.FTP()
                outputMsg += newFtp.connect(host, port, timeout)
                outputMsg += newFtp.login(user,password)
            except socket.error as se:
                raise FtpLibraryError('Socket error exception occured.')
            except ftplib.all_errors as e:
                raise FtpLibraryError(str(e))
            except Exception as e:
                raise FtpLibraryError(str(e))
            if self.printOutput:
                logger.info(outputMsg)
            self.__addNewConnection(newFtp, connId)
def ftp_connect ( self , host , user = 'anonymous' , password = 'anonymous@' , port = 21 , timeout = 30 , connId = 'default' ) : if connId in self . ftpList : errMsg = "Connection with ID %s already exist. It should be deleted before this step." % connId raise FtpLibraryError ( errMsg ) else : newFtp = None outputMsg = "" try : timeout = int ( timeout ) port = int ( port ) newFtp = ftplib . FTP ( ) outputMsg += newFtp . connect ( host , port , timeout ) outputMsg += newFtp . login ( user , password ) except socket . error as se : raise FtpLibraryError ( 'Socket error exception occured.' ) except ftplib . all_errors as e : raise FtpLibraryError ( str ( e ) ) except Exception as e : raise FtpLibraryError ( str ( e ) ) if self . printOutput : logger . info ( outputMsg ) self . __addNewConnection ( newFtp , connId )
Constructs FTP object, opens a connection and login.
        Call this function before any other (otherwise raises exception).
        Returns server output.
        Parameters:
            - host - server host address
            - user(optional) - FTP user name. If not given, 'anonymous' is used.
            - password(optional) - FTP password. If not given, 'anonymous@' is used.
            - port(optional) - TCP port. By default 21.
            - timeout(optional) - timeout in seconds. By default 30.
            - connId(optional) - connection identifier. By default equals 'default'
        Examples:
        | ftp connect | 192.168.1.10 | mylogin | mypassword |  |  |
        | ftp connect | 192.168.1.10 |  |  |  |  |
        | ftp connect | 192.168.1.10 | mylogin | mypassword | connId=secondConn |  |
        | ftp connect | 192.168.1.10 | mylogin | mypassword | 29 | 20 |
        | ftp connect | 192.168.1.10 | mylogin | mypassword | 29 |  |
        | ftp connect | 192.168.1.10 | mylogin | mypassword | timeout=20 |  |
        | ftp connect | 192.168.1.10 | port=29 | timeout=20 |  |  |