java 文件上传FTP

/**
	 * @param file
	 * @return
	 * 功能:上传FTP
	 */
	public static boolean tranUploadZIP(File file){
		boolean result = false;
		FileInputStream fis = null;
		try {
			//ftp客户端
			FTPClient ftp = new FTPClient();
			int reply;
			ftp.connect(RzprCommonBean.getValue("ftpIP"), Integer.parseInt(RzprCommonBean.getValue("ftpPost")));
			ftp.login(RzprCommonBean.getValue("ftpUserName"), RzprCommonBean.getValue("ftpPwd"));//这四个参数可配置
			ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
			reply = ftp.getReplyCode();
			if(!FTPReply.isPositiveCompletion(reply)){
				ftp.disconnect();
				return result;
			}
			ftp.changeWorkingDirectory("");
			ftp.setBufferSize(1024);
			ftp.setControlEncoding("UTF-8");
			//上传文件
			fis = new FileInputStream(file);
			ftp.storeFile(file.getName(), fis);
			fis.close();
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
			try {
				throw e;
			} catch (Exception e2) {
			}
		} finally {
			try {
				if(fis!=null){
					fis.close();
				}
			} catch (Exception e2) {
			}
		}
		return result;
	}

 

你可能感兴趣的:(java,文件上传FTP)