Steps to get the list of pdf files from FTP in IOS - ios

I'm new to IOS Development. This is the first time i'm hearing about FTP in IOS .I'm not getting, How to proceed further . I got this code https://developer.apple.com/library/ios/samplecode/SimpleFTPSample/Introduction/Intro.html .
But i didn't understand from this code .
I need to list the pdf files and folders from FTP . First i don't know how to establish the connection to FTP . Can any one please help me with steps.

I fyou look in ListController.m, listOrCancelAction is called when you click on List button.
In turn if you put a break point in startReceive you would see that
CFReadStreamCreateWithFTPURL is opening a "Open a CFFTPStream for the URL" with a specified URL.
I suggest you put a couple more break points and step through the code?
NSStreamDelegate is being used as callbacks when something is happening in particular
- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode
is called when connection is open or data is received.
Hope this is enough to get you started.
entryToAdd = [self entryByReencodingNameInEntry:(__bridge NSDictionary *) thisEntry encoding:NSUTF8StringEncoding];
in parseListData will have file name in kCFFTPResourceName which of course you can parse to find out if it is a PDF file. You may look at kCFFTPResourceType to see if you can use to determine file type, not sure.

Related

iOS Document Sharing: "Save to Dropbox" always fails

Posting after finding answer
After "rubber duck debugging" this answer a bunch, I finally came across the correct answer on a question that appears to me to be unrelated. I think this question (and its answer) are still relevant, so I'm posting the question and will post my own answer to hopefully help others like me.
I am creating a PDF in my iOS app that I would like to allow the user to export. For the purposes of this testing, I'm trying to save it to my personal Dropbox on a physical device.
I have turned on iTunes file sharing, and I can verify that the PDF file is being generated correctly, and when I copy it off of my device (iPad Pro Gen. 2 running iOS 11), I can open the PDF and it has the expected content and appearance.
I am able to get the document pop-up to display correctly, and I have options to share via:
Line 1: AirDrop
Line 2: Message, Mail, Add to Notes, (Facebook) Messenger, etc.
Line 3: Copy, Print, Save to Files, Save to Dropbox, etc.
No matter what I try to select (Save to Dropbox is the one I want to solve, but the issue seems universal), it fails. Of note, when I click Save to Dropbox, I do see the Dropbox panel display, but there is immediately a modal over top of the Save to Dropbox modal that says, "An unknown error occurred."
I have tried to look around and see how to get more information about this error, but I'm stumped. I'm not sure if it's correlated, but I get this message in the console:
[AXRun-PID] Client requesting unsuspension of PID:813 Name:<redacted>
Trying to google that error has proved unfruitful.
Here's the code where I generate the PDF and show the menu:
#pragma mark • Sharing Methods
- (void)showShareMenu {
NSArray *bookList = [BookManager bookList];
NSURL *pdfUrl = [PdfGenerator generatePdfFromBooks:bookList];
UIDocumentInteractionController *vc = [[UIDocumentInteractionController alloc] init];
vc.name = #"Booklet.pdf";
vc.URL = pdfUrl;
vc.UTI = #"com.adobe.pdf";
[vc presentOptionsMenuFromBarButtonItem:self.navigationItem.leftBarButtonItem animated:YES];
}
I've tried using UIDocumentInteractionController *vc = [UIDocumentInteractionController interactionControllerWithURL:pdfUrl]; instead of the one above, but the results are the same.
I tried making self the delegate of vc and then tried to implement the following methods:
- (void)documentInteractionController:(UIDocumentInteractionController *)controller
willBeginSendingToApplication:(nullable NSString *)application;
- (void)documentInteractionController:(UIDocumentInteractionController *)controller
didEndSendingToApplication:(nullable NSString *)application;
Neither of those methods ever fired.
Interestingly, though I think I've supplied the file name correctly based on what I've read, the name in the File textbook in the Save to Dropbox modal is a current timestamp (e.g., File Oct 28, 11 12 22 PM). The Dropbox modal stays up until I click "OK" on the "An unknown error occurred" modal, and then disappears immediately.
It seems like I'm somehow not providing the right information, but I'm not sure how. It seems like there ought to be a delegate method to indicate an error to me, but I don't see anything like that in the docs. (It is late, and I have been looking at this for hours, including reading several related tutorials, so I could have missed something obvious.)
I came across this answer as an example question while asking this current question.
It doesn't really ask the same question I have, nor did that user have the same error outputs I did. But, the linked answer did work for me, too.
The problem I had in the code above was that I was not keeping the UIDocumentInteractionController around after I created it. Adding a private property fixed this issue. So, the following code now works:
#pragma mark • Sharing Methods
- (void)showShareMenu {
NSArray *bookList = [BookManager bookList];
NSURL *pdfUrl = [PdfGenerator generatePdfFromBooks:bookList];
self.docController = [UIDocumentInteractionController interactionControllerWithURL:pdfUrl];
self.docController.name = #"Booklet.pdf";
self.docController.UTI = #"com.adobe.pdf";
[self.docController presentOptionsMenuFromBarButtonItem:self.navigationItem.leftBarButtonItem animated:YES];
}

Dropbox SDK bug

I was found something strange when I using Dropbox SDK 1.3.14
And here is how the bug happen , I put a dictionary tree like
/Comic/Author - Comic name (ex.浦澤直樹 - Monster)/Volume1/0.jpg , 1.jpg , ...)
And I want download the jpg to iOS app,And also create the same dictionary tree as Dropbox
So I create a dictionary tree in Document , It looks like
/var/mobile/Containers/Data/Application/12711FE6...290C7EAF50/Documents/Dropbox/Comic/浦澤直樹 - Monster/Volume1
Than I try to download the first page of comic
But it shows an error tell me the dictionary is not exist .
I use NSFileManager to check , It did exist .
Finally I find the problem
At this callback
- (void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata {
for (DBMetadata *file in metadata.contents) {
NSLog(#"File Path : %#",file.path);
}
}
Path will print like this
1./Comic
2./Comic/浦澤直樹 - Monster
3./Comic/浦澤直樹 - Monster/Volume1
4./Comic/浦澤直樹 - monster/Volume1/0.jpg
Now at the last file path , it gives me a different path name
I don't know why , but if I use this path to check is the parent dictionary is ready , It will return false.
So I never can download the file to specified path success
I was wonder does anyone got same issue like me ?
Dropbox itself is case-insensitive, with attempts to be case-preserving. However, due to various specifics, the API can't always return the expected case for every path component. So, for any file or folder metadata, the filename/last path component should have the preserved case, but other path components are not guaranteed to.
We realize this is non-ideal of course and are looking into ways to improve it, but I don't have a solution to offer right now.
If you need the preserved casing, you'll need to build it up from the last component in each parent entry.

How to set file name to NSData before uploading to server

I am currently making an app which converts an NSDictionary into a JSON file, in the intention of uploading it to a server. My issue is, is that I have no idea (let alone control) over what the name of the uploaded file is, how do I change/modify it?
Cheers,
Seb OH
This is something that should be handled by whatever FTP client library you are using.
For instance, FTPManager on GitHub (https://github.com/nkreipke/FTPManager) has the following method:
- (BOOL) uploadData:(NSData*)data withFileName:(NSString *)fileName toServer:(FMServer*)server;
That looks like it will fit your need just fine.

FTP for iOS, how to download from FTP protocol?

I have been using SampleFTP from Apple but I cannot understand the procedure, I mean, in other languages is simple as set the URL, Path, user and password then "navigate" and download or upload things to that Path... but I don't understand how to do in iOS... I don't have any NSFtp or whatever...
EDIT:
From the begining my #import "NetworkManager.h" does not work, error.
Can Use https://github.com/erica/iphone-3.0-cookbook-/tree/master/C13-Networking/15-FTP%20Helper
and
- (void) download
{
NSData *ftpData = [NSData dataWithContentsOfFile:[FTPHelper sharedInstance].filePath];
}
There is also the Karelia ConnectionKit. Free. Open Source and under active development.
There is no FTP inbuilt library for iOS,but you can find custom librariews for that like tihis one http://code.google.com/p/ios-ftp-server/ or http://www.chilkatsoft.com/ftp-objc.asp

Check if file is saved in documents directory

In my application, when I press on a button, I download a file from the internet, and then I read it. The only thing is that the file takes about five seconds to load, depending on the speed of the network, but since the file gets bigger and bigger, the time needed increases. If i save the file and after run the code to read it, the code runs but the file is not their, because it doen't wait the file to load. So I added an NSTimer of 6 seconds and it works. But if the file gets bigger I would need to change it. Is there a code to run the code to read the file, once the load is completed??
Thanks for the help
Since I use dropbox I can use this code (just found out):
- (void)restClient:(DBRestClient*)client loadedFile:(NSString*)localPath {
}
but it runs every time a file is downloaded, and I would like to run it for every 2 files loaded...
- (void)restClient:(DBRestClient*)client loadedFile:(NSString*)localPath {
NSLog(#"%#",localPath); //just to see the console log of what this method spits out
NSString *documents = ***DOC_DIRECTORY_METHOD***;
NSString *expectedFilePath = [documents stringByAppendingPathComponent:#"myDownloadedFile"];
if ([localPath isEqualToString:expectedFilePath]) {
//insert my read file method here
}
}
I don't know what the variable localPath will output, either the full path or just the name of the file. You might have to tweak this.
Good luck.

Resources