Uploading from FTP to Swift

I am trying to connect to an existing FTP server and upload and download folders and files inside those folders. I am lost on how to do this.

I have a function created below. It seems to be connecting to the FTP server, but I don't know what to do next.

If I can get a list of directories and store it in an array, I feel like I can move forward, but I'm not sure how to get the data from the FTP server.

func openFTPConnection()
{
    var url: CFStringRef
    url = "ftp://gg" as NSString
    var requestURL: CFURLRef
    requestURL = CFURLCreateWithString(kCFAllocatorDefault, url, nil);

    let ftpStream = CFReadStreamCreateWithFTPURL(kCFAllocatorDefault, requestURL).takeRetainedValue()
    var state = CFReadStreamOpen(ftpStream)

    if state == 0
    {
        println("False")
    }
    else
    {
        println("True")
    }

    var numBytesRead = 0
    var bufSize = 4096
    var buf = [UInt8](count: bufSize, repeatedValue: 0)

    do
    {
        numBytesRead = CFReadStreamRead(ftpStream, &buf, bufSize)
    }
        while( numBytesRead > 0 );


    CFReadStreamClose(ftpStream)

}

      

+3


source to share





All Articles