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

365
Views
usando SFTP en JSCH para cargar archivos, quiero saber cómo mostrar el progreso de la carga de archivos

mi página web tiene un botón para seleccionar los archivos, cuando se hace clic en el botón, enviará los datos de los archivos al servidor web, luego el servidor web creará un servicio SFTP que se crea a partir de JSCH, luego los archivos se enviarán al servidor remoto. Ahora quiero para saber cómo desarrollar la barra de progreso. Ya he desarrollado la barra de progreso cuando los archivos se envían al servidor web. Intento desarrollar la barra de progreso cuando los archivos se envían al servidor remoto, pero fallé. ingrese la descripción de la imagen aquí

la imagen uno es el proceso que envía archivos al servidor web. la imagen dos es el proceso que envía archivos al servidor remoto. ingrese la descripción de la imagen aquí

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

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' }) }) })

//aquí está el código que envía archivos al servidor remoto.

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