Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

528
Views
How to upload a file to FTP server with javascript?

For minimal example, I have
Host: 111.222.111.123
Username: user_name
Password: pass_word
File to upload is selected with HTML input element

I can upload the file manually to the target directory on the server with a client like FileZilla.

The target directory is where the file should be uploaded. Its location on the Internet is https://nameofsite/targetdir/, so the file should be reachable on the internet for anyone as https://nameofsite/targetdir/1.html.

But is it possible to upload the file to the server with javascript?
I tried this example taking to account @mcrdy455's answer, but anyway it's not clear what the FtpConnection is:

<input id="fileForUpload" type=file onchange="upload()">
<div id="fileContents"></div>
  
<script>
function upload() {
    var file = document.getElementById("fileForUpload").files[0];
    if (file) {
        var reader = new FileReader();
        reader.readAsText(file, "UTF-8");
        reader.onload = function (evt) {
            document.getElementById("fileContents").innerHTML = evt.target.result;
            
            var ftp = new FtpConnection("ftp://111.222.111.123/");
            ftp.login("user_name", "pass_word");
            ftp.put(file, "1.html");
            ftp.close();
            file.close();
        }
    }
}
</script>

Uncaught ReferenceError: FtpConnection is not defined

After searching on the Internet, I'm still not sure what project FtpConnection belongs to. Other examples use URLs instead of IP addresses (111.222.111.123).
E.g. Ftp.createCORSRequest('POST', "http://www.ftpjs.xyz/upload.aspx") in this one. I would like not to complicate things (with CORS) and use the 111.222.111.123 address.

If FileZilla can do the job, why couldn't javascript do it? How?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The JavaScript code can NOT access files from your filesystem, use an input type file, and read the file through the FileReader: You can fine more info on how to do this here, Once you have the correct file/blob object you code should work

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!