The ngCordova FileTransfer is not providing the HTTP status code when retrieving a file from an FTP server

I am attempting to retrieve a file from an FTP server using Cordova. To accomplish this, I have installed the ngCordova and Filetransfer plugins. Below is the snippet of code I am working with:

angular.module('TestApp', ['ionic', 'TestApp.controllers', 'charts.ng.justgage', 'pascalprecht.translate', 'ngCookies', 'ngCordova'])
var app = angular.module('TestApp.controllers', [])

app.controller('FileDownloadCtrl', function($scope, $timeout, $cordovaFileTransfer) {
$scope.downloadFile = function() {
    var url = "ftp://URL/somefile.xml";
    var filename = url.split("/").pop();
    alert(filename);
    var targetPath = cordova.file.externalRootDirectory + filename;
    var trustHosts = true;

    var options = new Object();
    var headers = { 'Authorization': 'Basic Login_cred' };
    options.headers = headers;

    alert(cordova.file.externalRootDirectory);
    alert(options.headers);
    $cordovaFileTransfer.download(url, targetPath, options, trustHosts)
      .then(function(result) {
          // Success!
          alert(JSON.stringify(result));
      }, function(error) {
          // Error
          alert(JSON.stringify(error));
      }, function (progress) {
          $timeout(function () {
              $scope.downloadProgress = (progress.loaded / progress.total) * 100;
          })
      });
}
});

The Angular.module can be found in a separate JS file within the actual code.

After running this code, the following alert messages are displayed:

  • somefile.xml
  • file://storage/emulated/0/
  • [object Object]
  • {"code":2,"source":","target":file:///storage/emulated/0/somefile.xml","http_status": null,"body":null,"exception":null}

I have attempted to download a file from a website hosted on the FTP (), which was successful. However, I suspect there may be an issue with the header setup in my code. Moreover, I tried including the Login_creds in the target URL like so: , but this approach did not work, possibly due to browser-specific restrictions.

Answer №1

After running into issues with ngCordova File Transfer and using ftp:// URLs, I found success by switching to a password-protected http solution.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring the foundations of web development with html and stylus

If you have experience with the roots platform, you are familiar with its default stack including jade, stylus, and coffee script. The documentation provides some information on using HTML, CSS, and pure JavaScript instead of the compiled languages, but d ...

Ways to retrieve JSON string from responsetext in JavaScript

After spending the entire day on this, I still can't figure it out. I have AJAX that fetches a JSON string from a PHP script, but now I need to work with it in JavaScript. Here's what I've tried: var xmlhttp; xmlhttp=new XMLHttpRequest(); ...

I continue to encounter an error every time I attempt to place an HTML nested div on a separate line

When I structure the HTML like this, I don't encounter any errors: <div class="game-card"><div class="flipped"></div></div> However, if I format it differently, I receive an error message saying - Cannot set property 'vi ...

JavaScript nested function scope loss issue is being faced

Could someone provide an explanation of the scope binding in this code snippet? window.name = "window"; object = { name: "object", method: function() { nestedMethod: function() { console.log(this.name); ...

Express: router.route continues processing without sending the request

I've implemented the following code in my Express application: var express = require('express'); // Initializing Express var app = express(); // Creating our app using Express var bodyParser = require(' ...

Storing and Manipulating a JavaScript Object with Vuex: A New Perspective

Consider a hypothetical JavaScript object class like this: class Car { var engineTurnedOn = false; ... public turnEngineOn() { engineTurnedOn = true } } If I want to turn the engine on, should I create an action called 'turnEngineOn&ap ...

Critical bug discovered in fundamental Vue.js component by Internet Explorer

My Vue.js-powered application is performing flawlessly in all web browsers, except for one... Upon attempting to launch it on Internet Explorer, a frustrating error appears: An anticipated identifier in vue.min.js, line 6 character 4872 Locating the spe ...

Press on the Edit option within the table using Protractor

Our application is built using Angular Js. The reports are displayed in a table format, with the last column reserved for editing the data. I am having trouble clicking on the Edit Link. Here is the code I have been using: element(by.id("table_id")).getT ...

What is the best way to handle newline characters ( ) when retrieving text files using AJAX?

When using an AJAX call to read a text file, I encountered an issue where it reads the \n\t and backslash symbols. These characters are not needed in the pure text message. How can I ignore or remove them for a clean text display? ...

Having Multiple Login Forms on a Single Page

I have encountered an issue with my login form code. It works perfectly as a single form, but I need to have 20 of these forms on one page. Despite my efforts to duplicate the code for each new form and adjusting the IDs, I am unable to make more than one ...

Issue: The module could not be located within the project or in any of the directories, including node_modules

Error: It seems we're having trouble resolving the module navigation/stack-routes from MainTabs.tsx file in gymzoo project directory. The path navigation/stack-routes could not be located within the project or node_modules directory. Greetings! I&apo ...

Storing JSON data from a Github Gist in an array using the AJAX method - a step-by-step guide

I'm experimenting with storing JSON data in a variable and then randomly accessing it. (Superhero Alias Generator) The JSON data can be found on GitHub gist below I decided to try using the ajax method for the first time, but it doesn't seem to ...

Trigger a Jquery sound when an HTML result is found and displayed

I am using a Jqgrid to display a table. Within the "return" column, along with other data, there is a span element like the following: <span class="return" id="ret0>4.25%</span> My webpage contains multiple instances of these spans: < ...

Cross-origin resource sharing (CORS) policy issue arises when the 'Access-Control-Allow-Origin' header is not included in the requested resource, especially when utilizing an iframe in a React

I am trying to link a website to a button using an iframe. This website allows access to all domain names. Below is the code for my button: <Button component={NavLink} activeClassName={classes.activeBtn} to="/searchEngine&qu ...

Efficient ways to clear all input fields within a React div component

import "./App.css"; import { useState } from "react"; import { useSelector, useDispatch } from "react-redux"; import { addUser} from "./features/Users"; function App() { const dispatch = useDispatch(); const use ...

Learn how to move a div inside another div using drag and drop, ensuring that the entire element moves along with it

I am trying to implement jQueryUI for my project. I have a list of components that I want to drag and drop into a grid system, similar to a designer tool. I am using the following code to make the div draggable: $( "#Component1" ).draggable(); Then I dro ...

Server with minimal setup requirements

While developing my Angular projects, I rely on lite server. This tool utilizes BrowserSync for tasks such as serving the site to localhost and enabling live reload functionality. In my project's root directory, there is a configuration file named bs ...

Receiving an absence of string or a null value from a text box

My goal is to test the functionality of an <input> element by entering text into a textbox and then displaying that data in the console. However, I am encountering issues with retrieving and printing the content. Additionally, I am interested in test ...

Duplicate the image from a specific div to another div, ensuring that only one clone is created

I'm trying to replicate an image in multiple spots within a frame, but I can only manage to get one instead of many. Can someone please tell me what I'm doing wrong? I am creating a map of terrain where I need to clone images from one div to anot ...

Issue with Jest Test Trigger Event Not Invoking Method

Currently, I am in the process of writing tests for my Vue application. One particular test involves a button that triggers a logout function. The goal is to determine if the function is executed when the button is clicked. Initially, I attempted to mock ...