Beispiel #1
0
 def test_26_compat(self):
     f = ftpslib.FTP_TLS()
     # 2.6 used to raise AttributeError:
     with self.assertRaises((
             socket.gaierror,
             socket.error,
     )):
         f.connect('no-such-host-dfgHJK56789', 990)
Beispiel #2
0
def active():
    ctx = SSL.Context('sslv23')
    f = ftpslib.FTP_TLS(ssl_ctx=ctx)
    f.connect('127.0.0.1', 39021)
    f.auth_tls()
    f.set_pasv(0)
    f.login('ftp', 'ngps@')
    f.prot_p()
    f.retrlines('LIST')
    f.quit()
Beispiel #3
0
    def ftpsConnect(self):

        timex = AlarmFTP('FTPS connection timeout')

        try:
            # gives 30 seconds to open the connection
            timex.alarm(30)

            ftps = ftpslib.FTP_TLS()

            ftps.connect(self.source.host, 21)
            # this should be an option... tls or ssl  ftps.auth_ssl()
            ftps.auth_tls()

            if self.source.ftp_mode == 'active':
                ftps.set_pasv(0)
            else:
                ftps.set_pasv(1)

            ftps.login(self.source.user, self.source.passwd)

            try:
                self.originalDir = ftps.pwd()
            except:
                (type, value, tb) = sys.exc_info()
                self.logger.warning("Unable to ftp.pwd (Type: %s, Value: %s)" %
                                    (type, value))

            timex.cancel()

            self.connected = True

            return ftps

        except FtpTimeoutException:
            timex.cancel()
            self.logger.warning(
                "FTPS connection timed out after 30 seconds...")

        except:
            timex.cancel()
            (type, value, tb) = sys.exc_info()
            self.logger.error(
                "Unable to connect to %s (user:%s). Type: %s, Value: %s" %
                (self.source.host, self.source.user, type, value))
Beispiel #4
0
 def test_lib(self):
     from M2Crypto import ftpslib
     ftpslib.FTP_TLS()
Beispiel #5
0
 def test_26_compat(self):
     from M2Crypto import ftpslib
     f = ftpslib.FTP_TLS()
     # 2.6 used to raise AttributeError:
     self.assertRaises(socket.gaierror, f.connect, 'no-such-host-dfgHJK56789', 990)
Beispiel #6
0
 def test_lib(self):
     ftpslib.FTP_TLS()
Beispiel #7
0
def FTPSDownloadFile(url,destination,
                     ssl_ctx=None,user=None,passw=None,
                     progressCB=None):
    """
    Download from the specified URL, storing the resulting file
    in the specified destination
    """
    log.debug('Entered FTPSDownloadFile: url=%s destination=%s',
                url, destination)

    if ssl_ctx is None:
        ssl_ctx = SSL.Context(DEFAULT_PROTOCOL)
    if user is None:  user = '******'
    if passw is None: passw = 'privateid'
    
    url = str(url)

    try:
        def cb(data,size,fl):
            try:
              global bytes_received
              fl.write(data)
              bytes_received += len(data)
              if progressCB:
                  cancelled = progressCB(float(bytes_received)/size,0)
                  if cancelled:
                      raise UserCancelled('User cancelled download')
            except UserCancelled:
              raise
            except:
              log.exception('Error in FTPSDownloadFile data callback')
              raise

        # parse url
        parts = urlparse.urlparse(url)
        hostport = parts[1]
        host,port=hostport.split(':')
        port = int(port)

        pathtofile = parts[2]

        # create ftp session
        f = ftpslib.FTP_TLS(ssl_ctx=ssl_ctx)
        #f.set_debuglevel(2)

        # connect to server and config connection
        f.connect(host,port)
        f.auth_tls()
        f.set_pasv(1)  
        f.prot_p()
        
        # login to server
        f.login(user,passw)

        # get file size
        siz = f.size(pathtofile)

        # open destination file and retrieve file contents
        fl = file(destination,'wb')
        callback = lambda data,size=siz,fp=fl: cb(data,size,fp)
        lin = f.retrbinary('retr %s' % pathtofile,callback)
        log.debug(lin)

        # transfer finished; close up
        if progressCB:
            progressCB(siz,1)
        fl.close()
        f.quit()
    except UserCancelled:
        raise
    except:
        log.exception('Error in FTPSDownloadFile')
        raise
Beispiel #8
0
def FTPSUploadFile(localfile,url,
                   ssl_ctx=None,user=None,passw=None,
                   progressCB=None):
    """
    Upload the specified file to the specified URL
    """

    log.debug('Entered FTPSUploadFile: localfile=%s url=%s',
                localfile, url)

    if ssl_ctx is None:
        ssl_ctx = SSL.Context(DEFAULT_PROTOCOL)
    if user is None:  user = '******'
    if passw is None: passw = 'privateid'
    
    try:
        # parse url
        parts = urlparse.urlparse(url)
        hostport = parts[1]
        host,port=hostport.split(':')
        port = int(port)

        # create ftp session
        f = ftpslib.FTP_TLS(ssl_ctx=ssl_ctx)
        #f.set_debuglevel(2)
        
        # connect and login
        f.connect(host,port)
        f.auth_tls()
        f.set_pasv(1)  
        f.prot_p()
        f.login(user,passw)
        
        # open local file and transfer file
        fl = FileWrapper(localfile,'rb',progressCB)

        # change to target directory
        f.voidcmd('cwd %s' % str(parts[2]))
        
        # upload the file
        remotefile = os.path.split(localfile)[-1]
        lin = f.storbinary('stor %s' % remotefile, fl)
        log.debug(lin)
        
        if progressCB:
            try:
                progressCB(localfile,
                       1,
                       fl.size,
                       1,0)
            except:
                log.exception('Error in progress callback')
        
        # transfer finished; close up
        fl.close()
        f.quit()
        
    except UserCancelled:
        raise
    except:
        log.exception('Error in FTPSUploadFile')
        raise