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

456
Views
How to send a file with FTP in JavaScript?

I want when a user uploads a file, this file should be sent to the server with FTP without pressing a button or submitting a form. I try to do that but it is not working.

Firstly, I created a function with time intervals, which checks whether the file input is empty or not. If it is not empty, it should send the file to the server.

var file = "/uploads/" + {{ api_id }}

this should be the address of the file on the server.

How can I do that or where is my mistake?

<input type="file" class="form-control-file" id="exampleFormControlFile1" name="bankStat1">

    <script>

        setInterval(displayHello, 1000);

        function displayHello() {
           var is_File = false
            if (document.getElementById("exampleFormControlFile1").files.length >= 1){
                is_File = true
                var file = "/uploads/" + {{ api_id }}

                var ftp = new FtpConnection("ftp://myftp/") ;
                ftp.login("myuser", "mypass");

                ftp.cd("uploads")
                ftp.put(file,document.getElementById("exampleFormControlFile1").files[0]) ;

                ftp.close() ;
                file.close() ;
            }
            console.log(is_File)

        }

    </script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I don't think there is a good solution for uploading files directly from client-side javascript to a server via FTP. The problem is that your FTP credentials need to be somewhere that the javascript can access them, but subsequently this means that that anyone with access to that javascript can simply use your FTP server as they please (a situation which is ripe for abuse.)

If you are simply trying to upload files to the server, HTML/HTTP provides file upload functionality on the client side and Django has the ability to do things with those files. If you have a server which is only accessible via FTP, I recommend that you upload the file to your django server and subsequently use a python FTP library to forward it from there. (I also recommend carefully validating the files that users have uploaded, as security problems abound from allowing client-supplied files to live on your server!)

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!