common-net包的ftp上传进度

//上传文件
public void uploadFile(HttpServletRequest request, HttpServletResponse response) throws Exception{
    MultipartHttpServletRequest fileRequest = (MultipartHttpServletRequest)request;
    MultipartFile file = fileRequest.getFile("file");
    String name = new String(file.getOriginalFilename().getBytes(), "ISO-8859-1");
    transSize = 0;
    totalSize = file.getSize();
    fileName = file.getOriginalFilename();
    PrintWriter out = response.getWriter();
    ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
    ftpClient.setFileTransferMode(FTP.STREAM_TRANSFER_MODE);
    int buff = 1024;
    ftpClient.setBufferSize(buff);
    int contentLen = 0;
    byte[] upload = new byte[1024];
    OutputStream output = ftpClient.appendFileStream(ftpClient.printWorkingDirectory() + "/" + name);
    InputStream input = file.getInputStream();
    try{
        do{
            contentLen = input.read(upload);
            output.write(upload, 0 ,contentLen);
	   transSize += contentLen;
        }while(contentLen >= 0);
    } catch(ArrayIndexOutOfBoundsException e){
        e.printStackTrace();
    } finally {
        input.close();
        output.flush();
        out.write("true");
        out.close();
    }
}

//取得进度		
public void getPercent(HttpServletRequest request, HttpServletResponse response) throws Exception{
    PrintWriter out = response.getWriter();
    out.write((double)transSize/(double)totalSize + "");
    out.close();
}


上传用到了spring的MVC,可以忽略。

你可能感兴趣的:(spring,mvc,.net)