Java 本地文件上传FTP服务器

    ……………………
      public static void uploadFtp(String url, int port, String username, String password, String remoteFilePath, String localFilePath){
        FTPClient ftpClient = new FTPClient();
        File localFile = new File(localFilePath);
        try {
            ftpClient.connect(url, port);
            ftpClient.login(username, password);
            ftpClient.enterLocalPassiveMode();
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
 
            FileInputStream inputStream = new FileInputStream(localFile);
 
            ftpClient.storeFile(remoteFilePath, inputStream);
 
            inputStream.close();
            ftpClient.logout();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (ftpClient.isConnected()) {
                try {
                    ftpClient.disconnect();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (localFile.exists()) {
		if(!localFile.delete()){
		    //System.out.println("本地文件删除失败,请手动删除imgs文件夹内的全部文件");
		}
	    }
        }
    }
……………………

Java 本地文件上传FTP服务器