STFTPNetwork is an FTP network library for iOS. You can use it to connect to the FTP server, manage your files, including query, create, delete, download, upload and other operations.
- iOS 8.0 or later (For iOS 8.0 before, maybe it can work, but I have not tested.)
- ARC
STFTPNetwork is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'STFTPNetwork'
In the source files where you need to use the library, import the header file:
#import <STFTPNetwork/STFTPNetwork.h>
Use the following function to connect to FTP server:
[STFTPNetwork connect:@"ftp://xxxx:xxxx" username:@"xxxx" password:@"xxxx" handler:^(BOOL success) {
NSLog(@"Connect FTP server success");
}];
Use the following function to query files:
[STFTPNetwork query:@"ftp://xxxx:xxxx/xxxx" successHandler:^(NSArray *results) {
NSLog(@"Query files success: %@", results);
} failHandler:^(STFTPErrorCode errorCode) {
NSLog(@"Query files failed: %ld", (long)errorCode);
}];
Use the fillowing function to new folder:
[STFTPNetwork create:@"ftp://xxxx:xxxx/xxxx" successHandler:^{
NSLog(@"New folder success");
} failHandler:^(STFTPErrorCode errorCode) {
NSLog(@"New folder failed: %ld", (long)errorCode);
}];
Use the following function to delete file or folder:
[STFTPNetwork remove:@"ftp://xxxx:xxxx/xxxx" successHandler:^{
NSLog(@"Delete file success");
} failHandler:^(STFTPErrorCode errorCode) {
NSLog(@"Delete file failed: %ld", (long)errorCode);
}];
Use the following function to download file:
[STFTPNetwork download:@"ftp://xxxx:xxxx/xxxx" progressHandler:^(unsigned long long bytesCompleted, unsigned long long bytesTotal) {
NSLog(@"Download progress: %.2f%%", bytesTotal > 0 ? bytesCompleted * 100.0 / bytesTotal : 0);
} successHandler:^(NSData *data) {
NSLog(@"Download file success: %@", data);
} failHandler:^(STFTPErrorCode errorCode) {
NSLog(@"Download file failed: %ld", (long)errorCode);
}];
Use the following function to upload file:
[STFTPNetwork upload:localFilePath urlString:@"ftp://xxxx:xxxx/xxxx" progressHandler:^(unsigned long long bytesCompleted, unsigned long long bytesTotal) {
NSLog(@"Upload progress: %.2f%%", bytesTotal > 0 ? bytesCompleted * 100.0 / bytesTotal : 0);
} successHandler:^{
NSLog(@"Upload file success");
} failHandler:^(STFTPErrorCode errorCode) {
NSLog(@"Upload file failed: %ld", (long)errorCode);
}];
Use the following function to disconnect FTP server:
[STFTPNetwork disconnect];
Suta, [email protected]