简单的写了个java对ftp的操作 用的是commons-net.jar包 FTPProxy.java public class FTPProxy{ public FTPProxy() { super(); ftpClient = new FTPClient(); } public FTPProxy(FTPBean entity) { this(); this.entity = entity; } private FTPBean entity; private FTPClient ftpClient; public void connection() { try { ftpClient.connect(entity.getServerIP()); ftpClient.login(entity.getUser(), entity.getPassword()); } catch (SocketException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public void download() { FileOutputStream fos = null; try { String remoteFile = entity.getSrcFile(); String remoteFileName = ""; if (0 == remoteFile.lastIndexOf("/")) { remoteFileName = remoteFile.substring(remoteFile .lastIndexOf("/") + 1); } else if (0 < remoteFile.lastIndexOf("/")) { remoteFileName = remoteFile.substring(remoteFile .lastIndexOf("/") + 1); String path = remoteFile.substring(0, remoteFile .lastIndexOf("/")); ftpClient.changeWorkingDirectory(path); } else { remoteFileName = remoteFile; } fos = new FileOutputStream(entity.getTargetFile()); ftpClient.setBufferSize(1024 * 8); ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); ftpClient.retrieveFile(remoteFileName, fos); } catch (IOException e) { e.printStackTrace(); } finally { try { fos.close(); ftpClient.disconnect(); } catch (IOException e) { e.printStackTrace(); } } } public void upload() { FileInputStream fis = null; try { File srcFile = new File(entity.getSrcFile()); fis = new FileInputStream(srcFile); ftpClient.setBufferSize(1024 * 8); ftpClient.setControlEncoding("GBK"); String ftpPath = entity.getFtpPath(); if(null!=ftpPath&&!"".equals(ftpPath)) { ftpClient.makeDirectory(ftpPath); ftpClient.changeWorkingDirectory(ftpPath); } ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); ftpClient.storeFile(entity.getTargetFile(), fis); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { fis.close(); ftpClient.disconnect(); } catch (IOException e) { e.printStackTrace(); } } } public void setEntity(FTPBean entity) { this.entity = entity; } public static void main(String[] args) { FTPBean ftpBean = new FTPBean(); ftpBean.setUser("admin"); ftpBean.setPassword("admin"); ftpBean.setServerIP("192.168.211.204"); ftpBean.setSrcFile("D://loadingPackageList.jsp"); ftpBean.setTargetFile("loadingPackageList.jsp"); ftpBean.setFtpPath("/admin_Test"); FTPProxy f = new FTPProxy(ftpBean); f.connection(); f.upload(); } } FTPBean.java public class FTPBean { private String serverIP; private String user; private String password; private String srcFile; private String targetFile; private String ftpPath; public String getServerIP() { return serverIP; } public void setServerIP(String serverIP) { this.serverIP = serverIP; } public String getUser() { return user; } public void setUser(String user) { this.user = user; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getSrcFile() { return srcFile; } public void setSrcFile(String srcFile) { this.srcFile = srcFile; } public String getTargetFile() { return targetFile; } public void setTargetFile(String targetFile) { this.targetFile = targetFile; } public String getFtpPath() { return ftpPath; } public void setFtpPath(String ftpPath) { this.ftpPath = ftpPath; } }