• Stars
    star
    131
  • Rank 275,867 (Top 6 %)
  • Language
    Objective-C
  • License
    Other
  • Created over 13 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

FTP client for iOS

General notes

You can use WhiteRaccoon to interact with FTP servers in one of two ways: either make a simple request and send it right away to the FTP server or add several requests to a queue and the queue will send them one by one in the order in which they were added.

WhiteRaccoon supports the following FTP operations:

  • Download file
  • Upload file (if the file is already on the server the delegate will be asked if the file should be overwritten)
  • Delete file
  • Delete directory (only if the directory is empty)
  • Create directory
  • List directory contents (returns an array of dictionaries, each dictionary has the keys described here)

IMPORTANT: In order for the library to compile and run, you have to include CFNetwork framework into your project.

Simple usage

Download file

    - download
    {

        //we don't autorelease the object so that it will be around when the callback gets called
        //this is not a good practice, in real life development you should use a retain property to store a reference to the request
        WRRequestDownload * downloadFile = [[WRRequestDownload alloc] init];
        downloadFile.delegate = self;
        
        //the path needs to be absolute to the FTP root folder.
        //full URL would be ftp://xxx.xxx.xxx.xxx/space.jpg
        downloadFile.path = @"/space.jpg";

        //for anonymous login just leave the username and password nil
        downloadFile.hostname = @"xxx.xxx.xxx.xxx";
        downloadFile.username = @"myuser";
        downloadFile.password = @"mypass";

        //we start the request
        [downloadFile start];

    }

    -(void) requestCompleted:(WRRequest *) request{
        //called after 'request' is completed successfully
        NSLog(@"%@ completed!", request);

        //we cast the request to download request
        WRRequestDownload * downloadFile = (WRRequestDownload *)request;

        //we get the image from the data
        UIImage * image = [UIImage imageWithData:downloadFile.receivedData];
    }

    -(void) requestFailed:(WRRequest *) request{
        //called after 'request' ends in error
        //we can print the error message
        NSLog(@"%@", request.error.message);
    }

Upload file

    - upload
    {

        //the upload request needs the input data to be NSData 
        //so we first convert the image to NSData
        UIImage * ourImage = [UIImage imageNamed:@"space.jpg"];
        NSData * ourImageData = UIImageJPEGRepresentation(ourImage, 100);


        //we create the upload request
        //we don't autorelease the object so that it will be around when the callback gets called
        //this is not a good practice, in real life development you should use a retain property to store a reference to the request
        WRRequestUpload * uploadImage = [[WRRequestUpload alloc] init];
        uploadImage.delegate = self;

        //for anonymous login just leave the username and password nil
        uploadImage.hostname = @"xxx.xxx.xxx.xxx";
        uploadImage.username = @"myuser";
        uploadImage.password = @"mypass";
        
        //we set our data
        uploadImage.sentData = ourImageData;
        
        //the path needs to be absolute to the FTP root folder.
        //full URL would be ftp://xxx.xxx.xxx.xxx/space.jpg
        uploadImage.path = @"/space.jpg";

        //we start the request
        [uploadImage start];

    }

    -(void) requestCompleted:(WRRequest *) request{

        //called if 'request' is completed successfully
        NSLog(@"%@ completed!", request);

    }

    -(void) requestFailed:(WRRequest *) request{

        //called after 'request' ends in error
        //we can print the error message
        NSLog(@"%@", request.error.message);

    }

    -(BOOL) shouldOverwriteFileWithRequest:(WRRequest *)request {

        //if the file (ftp://xxx.xxx.xxx.xxx/space.jpg) is already on the FTP server,the delegate is asked if the file should be overwritten 
        //'request' is the request that intended to create the file
        return YES;

    }

List directory contents

The file dictionary has several keys that describe most of the properties a file can have, from name to size. For a complete list of keys that the file dictionary has have a look here

    - listDirectoryContents
    {

        //we don't autorelease the object so that it will be around when the callback gets called
        //this is not a good practice, in real life development you should use a retain property to store a reference to the request
        WRRequestListDirectory * listDir = [[WRRequestListDirectory alloc] init];
        listDir.delegate = self;
        
        
        //the path needs to be absolute to the FTP root folder.
        //if we want to list the root folder we let the path nil or /
        //full URL would be ftp://xxx.xxx.xxx.xxx/
        listDir.path = @"/";

        listDir.hostname = @"xxx.xxx.xxx.xxx";
        listDir.username = @"myuser";
        listDir.password = @"mypass";


        [listDir start];

    }

    -(void) requestCompleted:(WRRequest *) request{

        //called after 'request' is completed successfully
        NSLog(@"%@ completed!", request);

        //we cast the request to list request
        WRRequestListDirectory * listDir = (WRRequestListDirectory *)request;

        //we print each of the files name
        for (NSDictionary * file in listDir.filesInfo) {
            NSLog(@"%@", [file objectForKey:(id)kCFFTPResourceName]);            
        }

    }

    -(void) requestFailed:(WRRequest *) request{
    
        //called if 'request' ends in error
        //we can print the error message
        NSLog(@"%@", request.error.message);

    }

Delete file or directory

    - deleteFileOrDirectory
    {

        //we don't autorelease the object so that it will be around when the callback gets called
        //this is not a good practice, in real life development you should use a retain property to store a reference to the request
        WRRequestDelete * deleteDir = [[WRRequestDelete alloc] init];

        //the path needs to be absolute to the FTP root folder.
        //if we are want to delete a directory we have to end the path with / and make sure the directory is empty
        //full URL would be ftp://xxx.xxx.xxx.xxx/dummyDir/
        deleteDir.path = @"/dummyDir/";

        deleteDir.hostname = @"xxx.xxx.xxx.xxx";
        deleteDir.username = @"myuser";
        deleteDir.password = @"mypass";

        //we start the request
        [deleteDir start];

    }

Create directory

    - createDirectory
    {

        //we don't autorelease the object so that it will be around when the callback gets called
        //this is not a good practice, in real life development you should use a retain property to store a reference to the request
        WRRequestCreateDirectory * createDir = [[WRRequestCreateDirectory alloc] init];

        //we set self as delegate, we must implement WRRequestDelegate
        createDir.delegate = self;

        //the path needs to be absolute to the FTP root folder.
        //full URL would be ftp://xxx.xxx.xxx.xxx/dummyDir/
        createDir.path = @"/dummyDir/";

        createDir.hostname = @"xxx.xxx.xxx.xxx";
        createDir.username = @"myuser";
        createDir.password = @"mypass";

        //we start the request
        [createDir start];

    }

    -(void) requestCompleted:(WRRequest *) request{

        //called if 'request' is completed successfully
        NSLog(@"%@ completed!", request);

    }

    -(void) requestFailed:(WRRequest *) request{

        //called if 'request' ends in error
        //we can print the error message
        NSLog(@"%@", request.error.message);

    }

Queue usage

Here is how you can use a queue request to create a directory and then add an image in it.

    - upload
    {

        //we alloc and init the our request queue
        //we don't autorelease the object so that it will be around when the callback gets called
        WRRequestQueue * requestsQueue = [[WRRequestQueue alloc] init];

        //we set the delegate to self
        requestsQueue.delegate = self;

        //we set the credentials and hostname
        //every request added to the queue will use them if it doesn't have its own credentials and/or hostname
        //for anonymous login just leave the username and password nil
        requestsQueue.hostname = @"xxx.xxx.xxx.xxx";
        requestsQueue.username = @"myuser";
        requestsQueue.password = @"mypass";


        //and now, we start to create our requests and add them to the queue
        //the requests will be executed in the order in which they were added, one by one


        //we first create a directory
        //we can safely autorelease the request object because the queue takes ownership of it in addRequest: method
        WRRequestCreateDirectory * createDir = [[[WRRequestCreateDirectory alloc] init] autorelease];

        //the path needs to be absolute to the FTP root folder.
        //full URL would be ftp://xxx.xxx.xxx.xxx/dummyDir/
        createDir.path = @"/dummyDir/";

        [requestsQueue addRequest:createDir];


        //then we upload the file in our newly created directory
        //the upload request needs the input data to be NSData 
        //so we first convert the image to NSData
        UIImage * ourImage = [UIImage imageNamed:@"space.jpg"];
        NSData * ourImageData = UIImageJPEGRepresentation(ourImage, 100);


        //we create the upload request
        WRRequestUpload * uploadImage = [[[WRRequestUpload alloc] init] autorelease];
        uploadImage.sentData = ourImageData;


        //we put the file in the directory we created with the previous request
        //the path needs to be absolute to the FTP root folder.
        //full URL would be ftp://xxx.xxx.xxx.xxx/dummyDir/image.jpg
        uploadImage.path = @"/dummyDir/image.jpg";


        [requestsQueue addRequest:uploadImage];

        //we start the request queue
        [requestsQueue start];

    }

    -(void) queueCompleted:(WRRequestQueue *)queue {

        //this will get called when all the requests are done
        //even if one or more requests end in error, this will still be called after the rest are completed
        NSLog(@"Done.");

    }

    -(void) requestCompleted:(WRRequest *) request{

        //called after 'request' is completed successfully
        NSLog(@"%@ completed!", request);

    }

    -(void) requestFailed:(WRRequest *) request{

        //called after 'request' ends in error
        //we can print the error message
        NSLog(@"%@", request.error.message);

    }

    -(BOOL) shouldOverwriteFileWithRequest:(WRRequest *)request {

        //if the file (ftp://xxx.xxx.xxx.xxx/dummyDir/image.jpg) is already on the FTP server,the delegate is asked if the file should be overwritten 
        //'request' is the request that intended to create the file
        return YES;

    }

More Repositories

1

Helm

A graph-based SwiftUI router
Swift
129
star
2

stencil

Customizable transactional and marketing email templates
JavaScript
87
star
3

Trellis

A lightweight, event-driven architectural framework
Swift
32
star
4

swift-toledo

A dependency injection library for Swift that statically generates resolvers at compile-time.
Swift
23
star
5

Hako

A barebone, functional core imperative shell container for Swift.
Swift
15
star
6

Pathcut

CGPath intersections for iOS and macOS
Swift
11
star
7

rust-aws-lambda-example

Backend for techpilot.dev
Rust
10
star
8

spoof-uuid-macos

A small utility to spoof the hardware uuid on macOS
Objective-C
6
star
9

interactiveanimations.swiftcraft.io

Swift
6
star
10

UIViewEasyPositioning

Demonstration of UIView+VRAlign category. An easy way to align and position views.
Objective-C
4
star
11

swiftui-async-context

A package that enables async and throwing calls from anywhere inside a view
Swift
2
star
12

Simple-OpenGL-Init

A very simple way to set up GLKitView without using the template provided by xcode
Objective-C
2
star
13

swift-any-codable

Codable type erasure implementation
Swift
1
star
14

StelarMonkey

Svg to Core Graphics
Swift
1
star
15

git-backup

Simple script for backing up multiple repositories with a generic commit message
Python
1
star
16

swift-peer-tunnel

A secure, peer-to-peer tunnel using Bonjour and the Network framework
Swift
1
star
17

ChangeUIImageColor

Demonstration of UIImage+VRColor category. A way to render your textures on-the-fly and minimising the graphic resources count.
Objective-C
1
star
18

swiftui-error-context

Error boundaries for SwiftUI
Swift
1
star