1

我已经使用这些类在 FTP 上上传文件。

我正在使用此方法进行上传

  - 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;

}

但我没有在 FTP 上成功上传文件。我也没有收到任何错误。

那么,如何通过FTP上传文件呢?

4

0 回答 0