title: Howto download file from ftp server using swift
body: <p>Hello I try to download an XML file from ftp server but I have a problem with the CFRreadStreamRead function. Because I don't know what I should set as "_ buffer: UnsafeMutablePointer" parameter. I got this function from <a href="https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFReadStreamRef/index.html#//apple_ref/c/func/CFReadStreamRead" rel="nofollow">apple documentation</a> On the code below you see how I currently try it. I hope you can help me. </p>
  
  <pre><code> public func openFTPConnection()
  {
      var url: CFStringRef
      url = "Test" as NSString
      var requestURL: CFURLRef
      requestURL = CFURLCreateWithString(kCFAllocatorDefault, url, nil);
  
      let ftpStream = CFReadStreamCreateWithFTPURL(kCFAllocatorDefault, requestURL).takeRetainedValue()
      var state = CFReadStreamOpen(ftpStream)
  
      if state == 0
      {
          println("Fehler beim verbinden")
      }
      else
      {
          println("Verbindung erfolgreich")
      }
  
      var numBytesRead = 0
      var bufSize = 4096
      var buf = [UInt8](count: bufSize, repeatedValue: 0)
  
      do
      {
          numBytesRead = CFReadStreamRead(ftpStream, buf, bufSize)
      }
      while( numBytesRead &gt; 0 );
  
  
      CFReadStreamClose(ftpStream)
  }
  </code></pre>