Giter VIP home page Giter VIP logo

lxftprequest's Introduction

LxFTPRequest

Installation

Only need add LxFTPRequest.h and LxFTPRequest.m to your project. Introduction

    A convenient FTP Request library. Support progress tracking, Breakpoint continuingly etc.
    Support FTP get resource list, download file, update file, 
    create directory or file, delete directory or file etc.
    Support progress tracking, Breakpoint continuingly, 
    auto check legitimacy of ftp address and local file path functions and so on.

Support

    Both support iOS and Mac OS X platforms.
    Minimum support iOS version: iOS 5.0
    Minimum support OS X version: Mac OS X 10.7

Podfile

    pod 'LxFTPRequest', '~> 1.0.0'

How to use

    #import "LxFTPRequest.h"

###Get resource list:

        LxFTPRequest * request = [LxFTPRequest resourceListRequest];
        request.serverURL = [[NSURL URLWithString:FTP_SCHEME_HOST]URLByAppendingPathComponent:SUB_DIRECTORY];
        request.username = USERNAME;
        request.password = PASSWORD;
        request.progressAction = ^(NSInteger totalSize, NSInteger finishedSize, CGFloat finishedPercent) {
        
            NSLog(@"totalSize = %ld, finishedSize = %ld, finishedPercent = %f", totalSize, finishedSize, finishedPercent); 
        };
        request.successAction = ^(Class resultClass, id result) {
                           
            NSArray * resultArray = (NSArray *)result;
            NSLog(@"resultArray = %@", resultArray);  
        };
        request.failAction = ^(CFStreamErrorDomain domain, NSInteger error) {
        
            NSLog(@"domain = %ld, error = %ld", domain, error);
        };
        [request start];

###Download resource:

    /**
        To implement breakpoint continuingly, you only need to guarantee
        the file downloaded part has not been modified in any way, 
        the ftp server support breakpoint continuingly
        and the file on server not change. 
        The download will continue from the last time progress.
        If you want to download resource from begin, you should delete the local downloaded part.
        [[NSFileManager defaultManager]removeItemAtPath:LOCAL_FILE_PATH error:&error];
    */

        LxFTPRequest * request = [LxFTPRequest downloadRequest];
        request.serverURL = [NSURL URLWithString:FTP_RESOURCE_ADDRESS];
        request.localFileURL = [NSURL fileURLWithPath:LOCAL_FILE_PATH];
        request.username = USERNAME;
        request.password = PASSWORD;
        request.progressAction = ^(NSInteger totalSize, NSInteger finishedSize, CGFloat finishedPercent) {
            
            NSLog(@"totalSize = %ld, finishedSize = %ld, finishedPercent = %f", totalSize, finishedSize, finishedPercent); 
        };
        request.successAction = ^(Class resultClass, id result) {
            
            NSLog(@"resultClass = %@, result = %@", resultClass, result);  
        };
        request.failAction = ^(CFStreamErrorDomain domain, NSInteger error) {
            
            NSLog(@"domain = %ld, error = %ld", domain, error);
        };
        [request start];

###Upload resource:

        LxFTPRequest * request = [LxFTPRequest uploadRequest];
        request.serverURL = [NSURL URLWithString:FTP_SCHEME_HOST]URLByAppendingPathComponent:FILE_PATH];
        request.localFileURL = [NSURL fileURLWithPath:LOCAL_FILE_SAVE_PATH];
        request.username = USERNAME;
        request.password = PASSWORD;
        request.progressAction = ^(NSInteger totalSize, NSInteger finishedSize, CGFloat finishedPercent) {
            
            NSLog(@"totalSize = %ld, finishedSize = %ld, finishedPercent = %f", totalSize, finishedSize, finishedPercent); 
        };
        request.successAction = ^(Class resultClass, id result) {
            
            NSLog(@"resultClass = %@, result = %@", resultClass, result);
        };
        request.failAction = ^(CFStreamErrorDomain domain, NSInteger error) {
            
            NSLog(@"domain = %ld, error = %ld", domain, error);
        };
        [request start];

###Create file or directory on ftp server:

        LxFTPRequest * request = [LxFTPRequest createResourceRequest];
        request.serverURL = [NSURL URLWithString:FTP_RESOURCE_PATH];    // directory path should be end up with '/'
        request.username = USERNAME;
        request.password = PASSWORD;
        request.successAction = ^(Class resultClass, id result) {
            
            NSLog(@"resultClass = %@, result = %@", resultClass, result);
        };
        request.failAction = ^(CFStreamErrorDomain domain, NSInteger error) {
            
            NSLog(@"domain = %ld, error = %ld", domain, error);
        };
        [request start];

###Delete file or directory on ftp server:

    /**
        The directory which is not empty CANNOT BE DELETED !!!
    */

        LxFTPRequest * request = [LxFTPRequest destoryResourceRequest];
        request.serverURL = [NSURL URLWithString:FTP_RESOURCE_PATH];
        request.username = USERNAME;
        request.password = PASSWORD;
        request.successAction = ^(Class resultClass, id result) {
            
            NSLog(@"resultClass = %@, result = %@", resultClass, result);
        };
        request.failAction = ^(CFStreamErrorDomain domain, NSInteger error) {
            
            NSLog(@"domain = %ld, error = %ld", domain, error);
        };
        [request start];

Be careful

Demo must config FTP address, username, password correctly. License

LxFTPRequest is available under the Apache License 2.0. See the LICENSE file for more info.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.