File download using FTP

Hello,

I have a problem with the FTP plugin (http://ionicframework.com/docs/native/ftp/). I want to download a series of files from an FTP one by one and once a file is downloaded the application should read the file and insert the data into a database. The problem is that the application reads the file before it is downloaded 100% and I do not know how to fix it.

According to the documentation, the download percentage is returned, but I do not know how to launch the function once it reaches 100%.

This is my code:

this.ftp.download(pathLocal+'lecturaData/'+filename, filename)
  			.then((resDL: any)=>{
		  		if (resDL == 1) {
			  		return this.FromFileToBBDD(this.file.externalDataDirectory+'lecturaData/', filename);
		  		}
  			})
		  .catch((error: any) => {
		  	console.error(error);
		  });

Thank you very much

@GabberMan did you manage to get this to work? I did the same way but the progress seems to only fire once. But the file got downloaded. Uploads give the same result too.

As a workaround I am using an interval to check if the downloaded file is written to storage. However, I can’t use the same interval to check for uploads.

Hello, I finally did the most horrible thing I could do… I set a waiting time to “wait” for the document to be downloaded, I could not find any solution.

I’m sorry I can’t help you

@GabberMan I did the same way too but I needed to upload and that didn’t work.

By the way, it seems to be an issue with Ionic typescript / angular version of the plugin. The upload function returns a promise but an observable is more appropriate. I used this one here which works - https://github.com/olaferlandsen/cordova-plugin-ftp

It has upload and download with progress :slight_smile:

1 Like

Nice! I’m going to try it, thanks! :smiley:

Hello, I’m facing the same issue but with upload, as what @arsyad said this is an issue with the native plugin itself, shouldn’t we need to post an issue?

Returns: Promise<any> Returns a promise. It will be triggered many times according the file’s size. The arg 0, 0.1xx, 0.2xx … 1 means the upload percent. When it reach 1, means success.

https://ionicframework.com/docs/native/ftp/#download

It is triggered multiple times, so I guess you could try an if statement in your the function…
But on the other hand I don’t know wether a promise could be triggered multiple times… it thought when its done the the state couldn’t be canged anymore?

Hello user5555, the if statement does not work, and I do not know what it means to say that the promise could be activated several times… once you get the ‘then’ return, the value does not change.

I’m confused too, the docs seem to be wrong or there is a bug.

I have no idea, but it seems that arsyad found the solution (File download using FTP) and it is what I have finally used.

It seems incredible that we have to use a cordova plugin to make it work for us, but that’s the way it is