/** * 上传文件到linux中 * @param multipartfile * @param path */ @Override public void uploadFile(MultipartFile multipartfile,String path) { // 获取文件名 String fileName = multipartfile.getOriginalFilename(); Connection conn = new Connection(deepLearningServerHost); System.out.println("连接开始"); SCPOutputStream os = null; FileInputStream fis = null; try { conn.connect(); boolean isAuthenticated = conn.authenticateWithPassword(deepLearningServerUsername,deepLearningServerPassword); if(!isAuthenticated){ System.out.println("连接建立失败"); } SCPClient scpClient = conn.createSCPClient(); String linuxPath = LIUNX_DEFAULT_PATH + path; File file = new File(fileName); byte[] za = multipartfile.getBytes(); os = scpClient.put(file.getName(),za.length,linuxPath,null); os.write(za, 0, za.length); os.flush(); System.out.println("upload ok"); } catch (IOException e) { e.printStackTrace(); }finally { try { if(fis != null){ fis.close(); } if(os != null){ os.close(); } if(conn != null){ conn.close(); } } catch (IOException e) { e.printStackTrace(); } } }