Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

458
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda