The ModMyTM Family of Sites:
ModMyMotoModMyiModMyGphone




 
 
Register or Connect with Facebook

Discuss AppStore Apps | Browse / Search Cydia | MMi Cydia Stats




  Apple Forums & iPhone Forums, Mods, Hacks, News, Themes, Downloads, and more! | ModMyi.com > 3rd Party Apps For iPhone | iPod Touch > iPhone / iPod Touch SDK | Development Discussion
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 09-05-2008, 10:10 AM
What's Jailbreak?
 
Join Date: Aug 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
FTP usage in iPhone applications?

I'm trying to make a sort of camera application. If the user takes a photo, he has te possibility to upload this photo to a FTP server.

Now i've read and tried a lot but it still doesn't works.

This is the code I have at the moment, it's being executed when the user clicks the "Upload picture" button. I got this code from the iPhone developer reference created by Apple so it should work..?

Code:
- (IBAction)emailPicture {
	NSString *pictureLocation = [NSHomeDirectory() stringByAppendingString:@"/Documents/Pictures/"];
	pictureLocation = [pictureLocation stringByAppendingString:[NSString stringWithFormat:@"%lu", currentPictureViewing]];
	pictureLocation = [pictureLocation stringByAppendingString:@".jpg"];
	/*
	UIImage *selectedImage = [UIImage imageWithContentsOfFile:pictureLocation];
	NSData *imageData = UIImageJPEGRepresentation(selectedImage, 100);
	 */
	NSString *ftpServer = @"domain.com";
	NSString *ftpUsername = @"user";
	NSString *ftpPassword = @"pass";
	CFWriteStreamRef       writeStream;
    CFReadStreamRef        readStream;
    CFStreamClientContext  context = { 0, NULL, NULL, NULL, NULL };
    CFURLRef               uploadURL, destinationURL;
    CFStringRef            fileName;
    Boolean                success = true;
    MyStreamInfo           *streamInfo;
	
	
	/* Create a CFURL from the upload directory string */
	destinationURL = CFURLCreateWithString(kCFAllocatorDefault, (CFStringRef)ftpServer, NULL);
	/* Copy the end of the file path and use it as the file name. */
	CFURLRef tmpFileName = (CFURLRef)pictureLocation;
	fileName = CFURLCopyLastPathComponent(tmpFileName);
	 assert(fileName != NULL);
	/* Create the destination URL by taking the upload directory and appending the file name. */
	uploadURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, destinationURL, fileName, false);
    assert(uploadURL != NULL);
    CFRelease(destinationURL);
    CFRelease(fileName);
	/* Create a CFReadStream from the local file being uploaded. */
    readStream = CFReadStreamCreateWithFile(kCFAllocatorDefault,(CFURLRef)pictureLocation);
    assert(readStream != NULL);
	/* Create an FTP write stream for uploading operation to a FTP URL. If the URL specifies a
	 directory, the open will be followed by a close event/state and the directory will have been
	 created. Intermediary directory structure is not created. */
    writeStream = CFWriteStreamCreateWithFTPURL(kCFAllocatorDefault, uploadURL);
    assert(writeStream != NULL);
    CFRelease(uploadURL);
	/* Initialize our MyStreamInfo structure, which we use to store some information about the stream. */
    MyStreamInfoCreate(&streamInfo, readStream, writeStream);
    context.info = (void *)streamInfo;
	/* CFReadStreamOpen will return success/failure.  Opening a stream causes it to reserve all the
	 system resources it requires.  If the stream can open non-blocking, this will always return TRUE;
	 listen to the run loop source to find out when the open completes and whether it was successful. */
    success = CFReadStreamOpen(readStream);
    if (success) {
        
        /* CFWriteStreamSetClient registers a callback to hear about interesting events that occur on a stream. */
        //success = CFWriteStreamSetClient(writeStream, kNetworkEvents, MyUploadCallBack, &context);
        success = TRUE;
		if (success) {
			
            /* Schedule a run loop on which the client can be notified about stream events.  The client
			 callback will be triggered via the run loop.  It's the caller's responsibility to ensure that
			 the run loop is running. */
            CFWriteStreamScheduleWithRunLoop(writeStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
            
            MyCFStreamSetUsernamePassword(writeStream, (CFStringRef)ftpUsername, (CFStringRef)ftpPassword);
            MyCFStreamSetFTPProxy(writeStream, &streamInfo->proxyDict);
            
            /* CFWriteStreamOpen will return success/failure.  Opening a stream causes it to reserve all the
			 system resources it requires.  If the stream can open non-blocking, this will always return TRUE;
			 listen to the run loop source to find out when the open completes and whether it was successful. */
            success = CFWriteStreamOpen(writeStream);
            if (success == false) {
                fprintf(stderr, "CFWriteStreamOpen failedn");
                MyStreamInfoDestroy(streamInfo);
            }
        } else {
            fprintf(stderr, "CFWriteStreamSetClient failedn");
            MyStreamInfoDestroy(streamInfo);
        }
    } else {
        fprintf(stderr, "CFReadStreamOpen failedn");
        MyStreamInfoDestroy(streamInfo);
    }	
}
In the headerfile I also have the following code:

Code:
#define kMyBufferSize  32768

/* MyStreamInfo holds the state of a particular operation (download, upload, or 
 directory listing.  Some fields are only valid for some operations, as explained 
 by their comments. */
typedef struct MyStreamInfo {
	
    CFWriteStreamRef  writeStream;              // download (destination file stream) and upload (FTP stream) only
    CFReadStreamRef   readStream;               // download (FTP stream), upload (source file stream), directory list (FTP stream)
    CFDictionaryRef   proxyDict;                // necessary to workaround <rdar://problem/3745574>, per discussion below
    SInt64            fileSize;                 // download only, 0 indicates unknown
    UInt32            totalBytesWritten;        // download and upload only
    UInt32            leftOverByteCount;        // upload and directory list only, number of valid bytes at start of buffer
    UInt8             buffer[kMyBufferSize];    // buffer to hold left over bytes
	
} MyStreamInfo;
When I compile, some weird errors comes:
Code:
"_MyCFStreamSetFTPProxy" referenced from:
-[appTabBarController emailPicture] in appTabBarController.o
"_MyStreamInfoCreate", referenced from:
-[appTabBarController, emailPicture] in appTabBarController.o
etc..
etc..
I can't click on those errors but I think they have something to do with some warnings I get:

Code:
warning: implicit declaration of function 'MyCFStreamSetFTPProxy'
warning: implicit declaration of function 'MyStreamInfoCreate'
etc...
etc...
I'm developing with Xcode and included the CFNetwork framework into my project. Also imported CFNetwork.h into my headerfile but that also doesn't fix the warnings/errors...

Can you please help me?

Last edited by Xino; 09-05-2008 at 10:13 AM..
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #2  
Old 09-10-2008, 08:11 AM
iPhone? More like MyPhone
 
Join Date: Oct 2007
Posts: 111
Thanks: 2
Thanked 17 Times in 14 Posts

In the code you've posted, I can't see the 'MyCFStreamSetFTPProxy' function definition.
You have to write it.
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
  #3  
Old 03-12-2009, 12:45 AM
What's Jailbreak?
 
Join Date: Sep 2008
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Ftp Upload Code Error

i think you need to add some of Frame work to Resolve the problem
Digg StumbleUpon Delicious Reddit Newsvine Google Yahoo Thanks Reply With Quote
Reply

  Apple Forums & iPhone Forums, Mods, Hacks, News, Themes, Downloads, and more! | ModMyi.com > 3rd Party Apps For iPhone | iPod Touch > iPhone / iPod Touch SDK | Development Discussion

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Go to Top
ModMyI

All times are GMT -6. The time now is 07:23 PM. Powered by vBulletin® Version 3.8.4
If you need Dedicated Server Hosting, you should check out SingleHop. | Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.0 Copyright © 2007-09 by ModMy, LLC. All rights reserved.

iPhone News / iPhone Forums / Apple News / Apple Forums / RSS / Contact Us / / Privacy Statement / Top