1、上传文件到FTP服务器,用FTPClient类,引入commons-net-3.1.jar包

2、参考代码:

//上传ftp
    public static boolean uploadFile(String filename) {
    	boolean success = false;
    	FTPClient ftp = new FTPClient();
    	try {
    		int reply;
    		ftp.connect("IP");//连接FTP服务器,默认端口
    		ftp.login("account", "pwd");//登录
    		reply = ftp.getReplyCode();
    		if (!FTPReply.isPositiveCompletion(reply)) {
    			ftp.disconnect();
    			return success;
    		}
    		ftp.changeWorkingDirectory("/");
    		FileInputStream in=new FileInputStream(new File("D://tmp//img//"+filename)); 
    		ftp.storeFile(filename, in);  
    		in.close();
    		ftp.logout();
    		success = true;
    	} catch (IOException e) {e.printStackTrace();} 
    	finally {
    		if (ftp.isConnected()) {
    			try {
    				ftp.disconnect();
    			} catch (IOException ioe) {}
    		}
    	}
    	return success;
    }