BlackRaccoon Check if file exist - ios

I'm using BlackRaccoon to upload a file within a server.
Prior to upload I'd like to understand if it is possible to check if the file that I upload is present or not!.
Is it possible?
Thank you,
Vincenzo

You could maybe use the List Directory Function
listDir = [[BRRequestListDirectory alloc] initWithDelegate: self];
listDir.path = #"/home/user/newdirectory/";
listDir.hostname = #"192.168.1.100";
listDir.username = #"yourusername";
listDir.password = #"yourpassword";
[listDir start];
then on the received list there is a
- (BOOL)fileExists:(NSString *)fileNamePath;
option.
Pass this the fileName to check whether your file already exists in the Directory.

Related

Can I upload an MP3 file to my server from iOS?

I was googling this question but nothing useful or current came up. I'd like to know if (and if, how) you can select an MP3 file (from itunes?) and upload the contents to one of my own servers on iOS (iphone & ipad app).
One of my clients is asking me if it's possible to do this, and I havn't found the answer yet.
Thanks in advance!
The short answer would be YES.
Here is a working solution for me. But you need to use a third party library. Then this is what you need to do:
Create a temp folder either in the NSDocuments directory or a temp directory.
Use MPMediaQuery to load the music files.
The object that you will get from the MPMediaQuery is an MPMediaItem. With this you can get the asset URL of the media item.
Code:
NSString *assetURL = [mediaItem valueForProperty:MPMediaItemPropertyAssetURL];
get the extension of with the asset URL
NSString *extension = [TSLibraryImport extensionForAssetURL:assetURL];
set a location URL (This will be the location where the mp3 music data will be imported).
NSString *locationURL = [[NSURL fileURLWithPath:[path stringByAppendingPathComponent:musicTitleYouWant]] URLByAppendingPathExtension:extension];
Now you can import the contents of the mp3 from to the directory you set earlier.
TSLibraryImport *libraryImport = [[TSLibraryImport alloc] init];
[libraryImport importAsset:assetURL toURL:locationURL completionBlock:^(TSLibraryImport *libraryImport)
{
if(libraryImport.status == AVAssetExportSessionStatusCompleted)
{
//Once complete the file will be store on the location URL you set earlier. Now you can get the file from that location and convert it to NSData and send it to the server. There are plenty of ways to do that.
}
else
{
//Here means import failed. :(
}
}];
Hope this helps. :)

How to copy an AWS S3 file from one bucket to another using iOS SDK

I'm using the AWS iOS SDK and have been able to do the upload / download file operations as outlined in the tutorials. Now I'm trying to copy a file from one bucket and paste it into another. I own both buckets and have access to them. I also want to delete the file from the first bucket after copying it (so technically this is a cut-paste operation) but I'm assuming the way to do that is copy, paste, delete the original.
After some digging it seems like the way to do this is through the AWSS3 -uploadPartCopy: function. It seems like this function uses an AWSS3UploadPartCopyRquest object which has 3 relevant input properties, the destination bucket (bucket), the destination key (key) and the source location (replicateSource), which seems to be a URL for the location of the object to be copied.
This seems to me like a really strange format for such a function, and I'm also not familiar with what Uploading a part means, i.e. does this have to be part of a multi-part upload? Do I need to start a multi-part upload before calling uploadPartCopy?
I'm also not sure this is the way to go about this. It seems like an overcomplicated solution to a relatively simple task. Am I on the right track here?
Just Refer below code. It gives you idea in detail for copy data from one bucket to another. In my case i want to copy multiple images from same bucket.
NSString *sourceBucket = #"treedev1234";
NSString *destinationBucket = #"treedev1234";
AWSS3 *s3 = [AWSS3 defaultS3];
AWSS3ReplicateObjectRequest *replicateRequest = [AWSS3ReplicateObjectRequest new];
for(int i = 0;i<feedModel.imageCount;i++){
replicateRequest.bucket = destinationBucket;
replicateRequest.key = [NSString stringWithFormat:#"posts/%d/%d.jpg",newpostid,i];
replicateRequest.replicateSource = [NSString stringWithFormat:#"%#/posts/%d/%d.jpg",sourceBucket,oldpostid,i];
replicateRequest.ACL = AWSS3ObjectCannedACLPublicReadWrite;
[[s3 replicateObject:replicateRequest] continueWithBlock:^id(AWSTask *task) {
if(task.error)
NSLog(#"The share request failed. error: [%#]", task.error);
return nil;
}];
There are two operations to copy an object: PUT Object - Copy and Upload Part - Copy. If the object is not too large, "PUT Object - Copy", which is mapped to - replicateObject:, is easier to implement.
Also, Amazon S3 has the Cross-Region Replication feature, which automatically replicates objects if your two buckets are not in the same region.

Objective Zip archives aren't opened by ArchiveUtility.app

I'm using ObjectiveZip library (which is a wrapper for MiniZip) in my iOS app. My app sends .zip archives to server, where they are processed manually by moderator. Here's my code for creating an archive:
NSString * zipfile = [Result zipfilePathWithResult:self];
ZipFile * zf = [[ZipFile alloc] initWithFileName:zipfile mode:ZipFileModeCreate];
ZipWriteStream * zws = [zf writeFileInZipWithName:#"report.xml" compressionLevel:ZipCompressionLevelNone];
[zws writeData:[xml dataUsingEncoding:NSUTF8StringEncoding]];
[zws finishedWriting];
for (NSString * name in mediaFiles)
{
ZipWriteStream * zws = [zf writeFileInZipWithName:name compressionLevel:ZipCompressionLevelNone];
[zws writeData:[files objectForKey:name]];
[zws finishedWriting];
}
[zf close];
Unfortunately, these archives aren't correctly processed by default OS X ArchiveUtility: it always unarchives my files into zip.cpgz, regardless of the actual content of archive (usually it's a .xml file and a few .jpg files).
However, some other applications on OS X and also on Windows are able to open my archives correctly, so the archive isn't actually broken.
Is there a way to make ObjectiveZip work with ArchiveUtility? Or maybe you can suggest any other objective-c library for creating .zip files which can do it. Thanks in advance!
Edit zip.c changing the parameters passed into each calls to zipOpenNewFileInZip3_64. The last parameter being passed into each method is a 1. Change it to a 0 and it will work
Changing the last parameter to zipOpenNewFileInZipX_64 function is one way to fix this but changing this parameter to 0 means setting zip64, i.e large file zipping capability, to false.
I was able to fix this by setting second parameter of zip64local_putValue call to (uLong)20(which is currently 45 in one case) inside the function Write_LocalFileHeader regardless of value of zi->ci.zip64.

Not deleting file from ftp using CFURLDestroyResource method in iphone

I have performed upload,download file from ftp using FTPHelper class. It's working perfectly.The issue generated in delete operation. While I'm deleting file from ftp server, nothing happens!. I don't know where I'm getting wrong. I have refered stackoverflow link to solve delete file from ftp but unable to do that.Below is my code to delete file from ftp.
pragma mark ***** Delete File From FTP
+(void)deleteFileFromFTPforItem:(NSString *) anItem
{
[sharedInstance deleteFileFromFTPforItem:anItem];
}
-(void)deleteFileFromFTPforItem:(NSString *) anItem
{
if (!self.uname || !self.pword) COMPLAIN_AND_BAIL(#"Please set user name and password first");
if (!self.urlString) COMPLAIN_AND_BAIL(#"Please set URL string first");
NSString *baseDeleteURL = [NSString stringWithFormat:#"%#/",self.urlString];
NSString *deleteFilePath = [baseDeleteURL stringByAppendingString:anItem];
CFURLRef deleteURL = (CFURLRef)[[NSURL alloc] initWithString:deleteFilePath];
//SInt32 *errorCode = NULL;
//CFURLDestroyResource(deleteURL, errorCode);
DeleteFile(deleteURL);
CFRelease(deleteURL);
}
static Boolean DeleteFile(CFURLRef urlToDelete)
{
Boolean success = true;
CFURLRef deleteURL = urlToDelete;
SInt32 *errorCode = NULL;
success = CFURLDestroyResource(deleteURL, errorCode);
return success;
}
Please give me a proper solution where am I going wrong.I have surfed lot of things but unable to get proper way to delete file from ftp.I have referred link to upload and download file to/from ftp.Your help would be appreciable.Thanks in advanced
To make a long story short, FTP support in NSURL and CFURL should be considered download-only. I don't think it ever fully worked, and ftp is thoroughly deprecated for any purposes other than anonymous downloads anyway, so it is unlikely to ever be fixed.
You can use other FTP access frameworks, as described in this question:
CFURLDestroyResource is now deprecated in iOS7. Anyone know what to use instead?
but really, you should probably be asking yourself whether using FTP is really the right way to do whatever you're trying to do, as opposed to (for example) WebDAV.

parsing XML located inside the project

This is the first time i'm going to parse an XML file with Xcode and it differs a bit from what I'm used to...
I read these 2 docs :
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/XMLParsing/Articles/UsingParser.html
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/XMLParsing/Articles/HandlingElements.html#//apple_ref/doc/uid/20002265-BCIJFGJI
I understand what's going on... But I still got one question. How can I do to parse an XML file which is located directly inside the project (I mean, for example in the resource file, where I usually put my images?). They usually show how to get the url of the XML file..But it's not the case here. It's going to be loaded directly on the iPad, among images and everything...
You Simply have to give the path of a local file :-
NSString *myFile= [documentsDirectory stringByAppendingPathComponent:#"youFile.xml"];
NSURL *xmlFile = [NSURL fileURLWithPath:myFile];
NSXMLParser *parser= [[NSXMLParser alloc] initWithContentsOfURL:xmlFile];
This is just an example implement your own login , use above two lines to get the path of local file.

Resources