ModMyMotoModMyiModMyGphone







  Apple Forums | ModMyi.com | iPhone, iPod, Mac, OS X, Mods, More > 3rd Party Apps For iPhone | iPod Touch > iPhone / iPod Touch SDK | Development Discussion
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
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 (permalink)  
Old 09-10-2008, 08:11 AM
Green Apple
 
Join Date: Oct 2007
Posts: 94
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
Reply

  Apple Forums | ModMyi.com | iPhone, iPod, Mac, OS X, Mods, More > 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
Forum Jump


Go to Top
ModMyI

All times are GMT -6. The time now is 11:04 PM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 | Dedicated Server Hosting by SingleHop | Copyright © 2007-08 by ModMy, LLC. All rights reserved.

RSS - Contact Us / / ModMyi Home / Archive / Privacy Statement - Top
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315