Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

362
Vistas
using SFTP in JSCH to upload files,I want to know how to display the progress about uploading files

my web page have a button to select the files,when the button clicked,it will send files data to webserver,then webserver will build a SFTP service which is built from JSCH,then the files will be sent to remote server.now I want to know how to develop the progress bar.I have already developed the progress bar when files send to web server.I try to develop the progress bar when files send to remote server but i failed. enter image description here

picture one is the process which sends files to webserver. picture two is the process which sends files to remote server. enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

// here is code which sends files to webserver. 
$(function() {

    $('#inputButton').on('click', function() {
        var fd = new FormData();
        var files_upload_num = document.getElementById('fileToUpload').files.length;
        if(files_upload_num == 0)
        {
            alert('请选择文件,完成上传!');
            return;
        }
        for(let i=0;i<files_upload_num;i++)
            fd.append("fileToUpload", document.getElementById('fileToUpload').files[i]);
        $.ajax({
            url: '<%=path%>/FileCl?method=submitFile',
            type: 'post',
            data: fd,
            processData: false,
            contentType: false,
            xhr: function() {
                var newxhr;
                if (window.XMLHttpRequest) {
                    newxhr = new XMLHttpRequest();
                } else {
                    // code for IE6, IE5
                    newxhr = new ActiveXObject("Microsoft.XMLHTTP");
                }
                newxhr.upload.onprogress = function(e) {
                    console.log(e)
                    var percent = ( (e.loaded / e.total).toFixed(2) ) * 100 + '%'
                    $('#progressBar').css('width', percent)
                    document.getElementById('progressBar').innerHTML = percent;
                }
                newxhr.addEventListener("load", uploadComplete, false);
                newxhr.addEventListener("error", uploadFailed, false);
                newxhr.addEventListener("abort", uploadCanceled, false);
                return newxhr
            },
            success: function(res) {
                console.log(res)
            },
            dataType: 'json'
        })
    })
})

//here is code which sends files to remote server.

        JSch jSch = new JSch();
        Session jSchSession = null;
        ChannelSftp chSftp = null;

        jSchSession = jSch.getSession(username, host, port);


        jSchSession.setPassword(password);


        Properties config = new Properties();
        config.put("StrictHostKeyChecking", "no");
        jSchSession.setConfig(config);


        jSchSession.setTimeout(1000*10);


        jSchSession.connect();


        chSftp = (ChannelSftp)jSchSession.openChannel("sftp");

        chSftp.connect();

        chSftp.setFilenameEncoding("UTF-8");



        sftpUtil sftpUtil = new sftpUtil(chSftp);


        for (FileItem item : fileItemList) {
            String filename = item.getName();
            if (filename == null || filename.trim().equals("")) {
                continue;
            }
            String id = UUID.randomUUID().toString().replace("-","");
            id = id.substring(0,8);

            File saveFile = new File(path,id+filename);
            fileNameList.add(id+filename);
            sftpUtil.upload("/home/liuyb/uploads",filename,item.getInputStream(),new uploadFileProgressMonitor(item.getSize()));
        }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda