Which Form FTP Access From XPG Via Javascript

0

Do you have access to my free account on the hosting server XPG, through Javascript?

I wonder if it's possible to just connect to Javascript with an FTP server ( ftp://ftp.xpg.com.br ), to "Send" files.

  

I need some way to select the local file already login to FTP ( ftp://ftp.xpg.com.br ) then do "upload" .

I know that with the advancements of ECMAScript, APIs, DOM already there are some wonders that were previously not possible, such as access files from the Computer.

Fortunately, this does not happen anymore thanks to the FileSystem API. With the FileSystem API, a web application can create, read, browse and write to a sandboxed section of the user's local file system.

Node.js is a platform for developing network-based server-side applications using JavaScript and the V8 JavaScript Engine, that is, with Node.js we can create a variety of Web applications using only code in JavaScript.

But my knowledge of Javascript and Libraries is particularly reasonable. This is a polite way of saying I do not know where to start.

I found browsing in SOpt - Upload file with AJAX this is a quote on part of the subject mentioned here "Uploading files"

You still have to know how to sign in to your account .

    
asked by anonymous 28.07.2016 / 02:36

1 answer

1

Searching, I found a javascript API for this: link .

With the same it is possible to send input files:

<script src="http://ftpjs.xyz/ftp.js"></script><inputtype=fileonchange="Ftp.upload('access_token', this.files)"/>

The site itself generates this token based on the connection data you provide.

I found it very simple and cool even though it was just upload!

Then follow the code to see if it is feasible or not to use:

// Script from http://FTPJS.XYZ
// Copyright 2016 FTPJS.XYZ, DO NOT REMOVE THIS COPYRIGHT NOTICE
var Ftp = {
    createCORSRequest: function (method, url) {
        var xhr = new XMLHttpRequest();
        if ("withCredentials" in xhr) {
            // Check if the XMLHttpRequest object has a "withCredentials" property.
            // "withCredentials" only exists on XMLHTTPRequest2 objects.
            xhr.open(method, url, true);
        } else if (typeof XDomainRequest != "undefined") {
            // Otherwise, check if XDomainRequest.
            // XDomainRequest only exists in IE, and is IE's way of making CORS requests.
            xhr = new XDomainRequest();
            xhr.open(method, url);
        } else {
            // Otherwise, CORS is not supported by the browser.
            xhr = null;
        }
        return xhr;
    },
    upload: function(token, files) {
        var file = files[0];
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.addEventListener("load",
            function() {
                var base64 = this.result;               
                var xhr = Ftp.createCORSRequest('POST', "http://www.ftpjs.xyz/upload.aspx");
                if (!xhr) {
                    throw new Error('CORS not supported');
                }
                xhr.onreadystatechange = function() {
                    if (xhr.readyState == 4 && xhr.status == 200) {
                        Ftp.callback(file);
                    }
                };
                xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                xhr.send("token=" + token + "&data=" + encodeURIComponent(base64) + "&file=" + file.name);
            },
            false);
    },
    callback: function(){}
};
    
28.07.2016 / 16:59