FTP text transfer protocol and FTP text transfer protocol

Source: Internet
Author: User
Tags ftp file ftp file transfer ftp file transfer protocol what is ftp

FTP text transfer protocol and FTP text transfer protocol

I have always used AFNetworking to upload images in my development project. Recently, the boss said that I should use FTP to upload images, and there is very little information on the Internet. After all, this upload method is not used much now, it took a day to learn the FTP file transfer protocol. My personal understanding is as follows:

What is FTP?

FTP is short for File Transfer Protocol (File Transfer Protocol ". It is used for controlling two-way transmission of files over the Internet. It is also an Application ). There are different FTP applications based on different operating systems, and all these applications comply with the same protocol to transfer files. During FTP usage, users often encounter two concepts: "Download" and "Upload ). "Download" is to copy files from a remote host (which can be understood as another server) to your computer; "Upload" is to copy the file from your computer to a remote host. In Internet language, users can upload (download) files to (from) remote hosts through client programs. (From Baidu) Note: if the local FTP address is used, the local host is equivalent to a remote host.

I have uploaded the image in the album to FTP:

1. You must enable FTP before uploading.

If you use FTP, the mac OS of a later version is disabled by default. You can run the following command to enable it:

Sudo-s launchctl load-w/System/Library/LaunchDaemons/ftp. plist

Correspondingly, to disable it:

Sudo-s launchctl unload-w/System/Library/LaunchDaemons/ftp. plist Mac comes with server tools to view FTP files: tutorial http://jingyan.baidu.com/article/7c6fb42869cd2380642c90af.html (the user name and password to access is the user name and password to log on to mac ).

 

2. A third-party FTP File Management SDK https://github.com/ZCasey/GRRequestsManager needs to be downloaded before the trojan code

3. Start the trojan code!

Idea: a. Save the photo from the album to a specified folder (in the app)

B. Create a folder in ftp and upload the image to this folder.

Data = dataImage; NSDateFormatter * formate = [[NSDateFormatter alloc] init]; formate. dateFormat = @ "yyyy-MM-dd HH: mm: ss"; NSString * documentPath = [NSHomeDirectory () stringByAppendingPathComponent: @ "document"]; // open the file manager NSFileManager * fileMange = [NSFileManager defaultManager]; // create a folder [fileMange createDirectoryAtPath: documentPath withIntermediateDirectories: YES attributes: nil error: nil]; // create the file NSString * localpath = [NSString stringWithFormat: @ "% @/%@.jpg", documentPath, [formate stringFromDate: [NSDate date]; NSLog (@ "image PATH % @:", localpath) [fileMange createFileAtPath: [NSString stringWithFormat: @ "% @/%@.jpg", documentPath, [formate stringFromDate: [NSDate date] contents: data attributes: nil];
// (Header file # import "GRRequestsManager. h" is required ")
GRRequestsManager * requestManager = nil; // set the FTP request requestManager = [[GRRequestsManager alloc] initWithHostname: @ "ftp: // ********" user: @ "******" password: @ "**********"]; // FTP sets the proxy requestManager. delegate = self; // create a directory layer to upload a file [requestManager addRequestForCreateDirectoryAtPath: @ "ZZTest"]; [requestManager startProcessingRequests]; NSString * ftpPath = [NSString stringWithFormat: @ "ZZTest/111.jpg"] [self. requestManager addRequestForUploadFileAtLocalPath: localpath toRemotePath: ftpPath]; [self. requestManager startProcessingRequests];

GRRequestsManager proxy method

# Pragma mark-author-(void) requestsManager :( id <GRRequestsManagerProtocol>) requestsManager didScheduleRequest :( id <GRRequestProtocol>) request {NSLog (@ "required requestsManager: response :");} -(void) requestsManager :( id <strong>) requestsManager submit :( id <GRRequestProtocol>) request listing :( NSArray *) listing {NSLog (@ "2_requestsManager: didCompleteListingRequest: listing: \ n % @ ", listing);}-(void) requestsManager :( id <GRRequestsManagerProtocol>) requestsManager didCompleteCreateDirectoryRequest :( id <GRRequestProtocol>) request {// NSLog (@ "3_requestsManager: didCompleteCreateDirectoryRequest:") ;}- (void) requestsManager :( id <GRRequestsManagerProtocol>) requestsManager succeeded :( id <GRRequestProtocol>) request {NSLog (@ "4_requestsManager: response:");}-(void) requestsManager :( id <GRRequestsManagerProtocol>) requestsManager didCompletePercent :( float) percent forRequest :( id <GRRequestProtocol>) request {NSLog (@ "5_requestsManager: didCompletePercent: forRequest: % f", percent);}-(void) requestsManager :( id <strong>) requestsManager didCompleteUploadRequest :( id <strong>) request {// NSLog (@ "6_requestsManager: didCompleteUploadRequest:") ;}- (void) requestsManager :( id <GRRequestsManagerProtocol>) requestsManager didCompleteDownloadRequest :( id <response>) request {NSLog (@ "7_requestsManager: didCompleteDownloadRequest:");}-(void) requestsManager :( id <GRRequestsManagerProtocol>) requestsManager principal :( NSString *) path forRequest :( id <response>) request error :( NSError *) error {NSLog (@ "8_requestsManager: didFailWritingFileAtPath: forRequest: error: \ n % @", error);}-(void) requestsManager :( id <strong>) requestsManager didFailRequest :( id <GRRequestProtocol>) request withError :( NSError *) error {NSLog (@ "9_requestsManager: didFailRequest: withError: \ n % @", error );}

 

 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.