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

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

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 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