Permalink
Browse files

S3 upload support fairly stable.

  • Loading branch information...
nrj committed May 29, 2010
1 parent b1eb49b commit 25f7b7a0c86112553ada1381c5ebb94a0e7cf131
View
@@ -41,21 +41,6 @@ - (void)dealloc
}
-/*
- * Generates a new curl_easy_handle with FTP-specific options set.
- *
- * See http://curl.haxx.se/libcurl/c/libcurl-easy.html
- */
-- (CURL *)newHandle
-{
- CURL *handle = [super newHandle];
-
- curl_easy_setopt(handle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L);
-
- return handle;
-}
-
-
- (NSString *)protocolPrefix
{
return @"ftp";
View
@@ -9,6 +9,7 @@
#import "S3UploadOperation.h"
#import "Upload.h"
+
@implementation CurlS3
View
@@ -7,7 +7,7 @@
#import <Cocoa/Cocoa.h>
#import "CurlFTP.h"
-
+#import "CurlClient.h"
extern int const DEFAULT_SFTP_PORT;
View
@@ -117,7 +117,7 @@ - (Upload *)uploadFilesAndDirectories:(NSArray *)filesAndDirectories toHost:(NSS
[upload setHostname:hostname];
[upload setUsername:username];
[upload setPassword:password];
- [upload setPath:[directory pathForFTP]];
+ [upload setPath:directory];
[upload setPort:port];
[self upload:upload];
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -6,6 +6,7 @@
//
#import <Cocoa/Cocoa.h>
+#import <objective-curl/objective-curl.h>
@class Upload, CurlFTP, CurlSFTP, CurlSCP, CurlS3;
@@ -23,6 +24,7 @@
IBOutlet NSTextField *hostnameField;
IBOutlet NSTextField *usernameField;
IBOutlet NSTextField *passwordField;
+ IBOutlet NSTextField *remoteDirField;
IBOutlet NSButton *connectButton;
IBOutlet NSTextField *fileField;
IBOutlet NSProgressIndicator *progressBar;
View
@@ -6,7 +6,7 @@
//
#import "TestController.h"
-#import <objective-curl/objective-curl.h>
+
@implementation TestController
@@ -15,21 +15,21 @@ @implementation TestController
- (void)awakeFromNib
-{
- NSLog([CurlObject libcurlVersion]);
+{
+ NSLog(@"Version: %@", [CurlObject libcurlVersion]);
ftp = [[CurlFTP alloc] init];
[ftp setVerbose:NO];
[ftp setShowProgress:YES];
[ftp setDelegate:self];
sftp = [[CurlSFTP alloc] init];
- [sftp setVerbose:NO];
+ [sftp setVerbose:YES];
[sftp setShowProgress:YES];
[sftp setDelegate:self];
scp = [[CurlSCP alloc] init];
- [scp setVerbose:NO];
+ [scp setVerbose:YES];
[scp setShowProgress:YES];
[scp setDelegate:self];
@@ -46,7 +46,7 @@ - (IBAction)uploadFile:(id)sender
id <CurlClient>client = nil;
- switch([typeSelector selectedColumn])
+ switch([typeSelector selectedRow])
{
default:
case 0:
@@ -67,7 +67,7 @@ - (IBAction)uploadFile:(id)sender
toHost:[hostnameField stringValue]
username:[usernameField stringValue]
password:[passwordField stringValue]
- directory:@"nickjensen"];
+ directory:[remoteDirField stringValue]];
// [newUpload setUsePublicKeyAuth:YES];
// [newUpload setPrivateKeyFile:[@"~/.ssh/id_rsa" stringByExpandingTildeInPath]];
@@ -96,14 +96,14 @@ - (void)uploadDidBegin:(Upload *)record
- (void)uploadDidProgress:(Upload *)record toPercent:(NSNumber *)percent;
{
- NSLog(@".");
+// NSLog(@".");
// NSLog(@"Uploading %d of %d Files", [upload totalFilesUploaded], [upload totalFiles]);
- NSLog(@" Current File: %.0f of %.0f Bytes Uploaded (%d%%)",
- [[record currentTransfer] totalBytesUploaded], [[record currentTransfer] totalBytes], [[record currentTransfer] percentComplete]);
-
- NSLog(@"Total Progress: %.0f of %.0f Bytes Uploaded (%d%%)",
- [record totalBytesUploaded], [record totalBytes], [record progress]);
- NSLog(@"");
+// NSLog(@" Current File: %.0f of %.0f Bytes Uploaded (%d%%)",
+// [[record currentTransfer] totalBytesUploaded], [[record currentTransfer] totalBytes], [[record currentTransfer] percentComplete]);
+//
+// NSLog(@"Total Progress: %.0f of %.0f Bytes Uploaded (%d%%)",
+// [record totalBytesUploaded], [record totalBytes], [record progress]);
+// NSLog(@"");
}
@@ -10,24 +10,38 @@
@implementation NSFileManager (MimeType)
-
+ (NSString *)mimeTypeForFileAtPath:(NSString *)path
{
- NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]];
- NSURLResponse *resp = nil;
- NSError *err = nil;
-
- [NSURLConnection sendSynchronousRequest:req
- returningResponse:&resp
- error:&err];
+ BOOL isDir = NO;
+ NSFileManager *mgr = [[NSFileManager alloc] init];
+ NSString *mimeType = @"";
- if (err)
+ if ([mgr fileExistsAtPath:path isDirectory:&isDir] && isDir)
+ {
+ mimeType = @"application/x-directory";
+ }
+ else
{
- NSLog(@"Error trying to get MimeType of file: %@ - %@", path, [err description]);
- return @"";
+ NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]];
+ NSURLResponse *resp = nil;
+ NSError *err = nil;
+
+ [NSURLConnection sendSynchronousRequest:req
+ returningResponse:&resp
+ error:&err];
+ if (!err)
+ {
+ mimeType = [resp MIMEType];
+ }
+ else
+ {
+ NSLog(@"Error trying to get MimeType of file: %@ - %@", path, [err description]);
+ }
}
- return [resp MIMEType];
+ [mgr release];
+
+ return mimeType;
}
@end
@@ -10,8 +10,7 @@
@interface NSString (PathExtras)
-- (NSString *)pathForFTP;
-- (NSString *)appendPathForFTP:(NSString *)path;
+- (NSString *)stringByAddingTildePrefix;
- (NSString *)stringByRemovingTildePrefix;
@end
@@ -10,7 +10,8 @@
@implementation NSString (PathExtras)
-- (NSString *)pathForFTP
+
+- (NSString *)stringByAddingTildePrefix
{
if ([self isEqualToString:@""])
return @"~/";
@@ -23,20 +24,9 @@ - (NSString *)pathForFTP
else
path = [NSMutableString stringWithString:self];
- // SFTP requires a trailing slash.
- if(![[path substringFromIndex:([path length] - 1)] isEqualToString:@"/"])
- [path appendString:@"/"];
-
return path;
}
-- (NSString *)appendPathForFTP:(NSString *)path;
-{
- if ([path isEqualToString:@"."])
- return self;
-
- return [[self stringByAppendingPathComponent:path] pathForFTP];
-}
- (NSString *)stringByRemovingTildePrefix
{
@@ -48,4 +38,5 @@ - (NSString *)stringByRemovingTildePrefix
return self;
}
+
@end
View
@@ -6,6 +6,7 @@
#import "CurlSCP.h"
+#import "CurlS3.h"
#import "Upload.h"
#import "FileTransfer.h"
#import "UploadDelegate.h"
View
@@ -8,13 +8,16 @@
#import <Cocoa/Cocoa.h>
#import <stdio.h>
#import <sys/stat.h>
-
+#import <curl/curl.h>
@interface FileTransfer : NSObject
{
NSString *localPath;
NSString *remotePath;
+ struct curl_slist *headers;
+ struct curl_slist *postQuote;
+
BOOL isEmptyDirectory;
BOOL fileNotFound;
@@ -41,10 +44,24 @@
- (id)initWithLocalPath:(NSString *)aLocalPath remotePath:(NSString *)aRemotePath;
+- (struct curl_slist *)headers;
+
+- (void)appendHeader:(const char *)header;
+
+- (void)cleanupHeaders;
+
+- (struct curl_slist *)postQuote;
+
+- (void)appendPostQuote:(const char *)quote;
+
+- (void)cleanupPostQuotes;
+
- (FILE *)getHandle;
- (int)getInfo:(struct stat *)info;
- (NSString *)getEmptyFilePath;
++ (NSString *)emptyFilename;
+
@end
View
@@ -33,6 +33,9 @@ - (id)initWithLocalPath:(NSString *)aLocalPath remotePath:(NSString *)aRemotePat
[self setLocalPath:aLocalPath];
[self setRemotePath:aRemotePath];
+ headers = NULL;
+ postQuote = NULL;
+
percentComplete = 0;
totalBytes = 0;
totalBytesUploaded = 0;
@@ -41,11 +44,64 @@ - (id)initWithLocalPath:(NSString *)aLocalPath remotePath:(NSString *)aRemotePat
return self;
}
+
+- (void)dealloc
+{
+ [localPath release]; localPath = nil;
+ [remotePath release]; remotePath = nil;
+ if (headers) {
+ curl_slist_free_all(headers); headers = nil;
+ }
+ if (postQuote) {
+ curl_slist_free_all(postQuote); postQuote = nil;
+ }
+ [super dealloc];
+}
+
+
- (NSString *)getEmptyFilePath
{
- NSString *str = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Contents/Frameworks/objective-curl.framework/Resources/.empty"];
+ NSArray *pathComponents = [NSArray arrayWithObjects:[[NSBundle bundleForClass:[self class]] bundlePath], @"Resources", [FileTransfer emptyFilename], NULL];
- return str;
+ return [NSString pathWithComponents:pathComponents];
+}
+
+- (struct curl_slist *)headers
+{
+ return headers;
+}
+
+- (void)appendHeader:(const char *)header
+{
+ headers = curl_slist_append(headers, header);
+}
+
+- (void)cleanupHeaders
+{
+ if (headers)
+ {
+ curl_slist_free_all(headers);
+ headers = NULL;
+ }
+}
+
+- (struct curl_slist *)postQuote
+{
+ return postQuote;
+}
+
+- (void)appendPostQuote:(const char *)quote
+{
+ postQuote = curl_slist_append(postQuote, quote);
+}
+
+- (void)cleanupPostQuotes
+{
+ if (postQuote)
+ {
+ curl_slist_free_all(postQuote);
+ postQuote = NULL;
+ }
}
- (FILE *)getHandle
@@ -64,6 +120,7 @@ - (FILE *)getHandle
return fh;
}
+
- (int)getInfo:(struct stat *)info
{
if([self isEmptyDirectory])
@@ -76,9 +133,16 @@ - (int)getInfo:(struct stat *)info
}
}
+
- (NSString *)description
{
return [NSString stringWithFormat:@"<FileTransfer localPath='%@' remotePath='%@' isEmptyDirectory='%d'", localPath, remotePath, isEmptyDirectory];
}
+
++ (NSString *)emptyFilename
+{
+ return @".empty";
+}
+
@end
Oops, something went wrong.

0 comments on commit 25f7b7a

Please sign in to comment.