{"id":20573535,"url":"https://github.com/lightweight-component/aj-ftp","last_synced_at":"2026-07-06T10:30:59.862Z","repository":{"id":299540139,"uuid":"1003353149","full_name":"lightweight-component/aj-ftp","owner":"lightweight-component","description":" A Lightweight FTP Client","archived":false,"fork":false,"pushed_at":"2025-06-17T03:23:38.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-17T04:39:37.730Z","etag":null,"topics":["ftp","ftp-client","java-ftp"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lightweight-component.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-17T02:53:24.000Z","updated_at":"2025-06-17T03:23:41.000Z","dependencies_parsed_at":"2025-06-17T04:20:56.040Z","dependency_job_id":"a072705c-9d67-4fab-9159-58d7d85b2ae5","html_url":"https://github.com/lightweight-component/aj-ftp","commit_stats":null,"previous_names":["lightweight-component/aj-ftp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lightweight-component/aj-ftp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightweight-component%2Faj-ftp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightweight-component%2Faj-ftp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightweight-component%2Faj-ftp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightweight-component%2Faj-ftp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lightweight-component","download_url":"https://codeload.github.com/lightweight-component/aj-ftp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightweight-component%2Faj-ftp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35187624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-06T02:00:07.184Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ftp","ftp-client","java-ftp"],"created_at":"2024-11-16T05:28:02.258Z","updated_at":"2026-07-06T10:30:59.835Z","avatar_url":"https://github.com/lightweight-component.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Maven Central](https://img.shields.io/maven-central/v/com.ajaxjs/aj-ftp?label=Latest%20Release)](https://central.sonatype.com/artifact/com.ajaxjs/aj-ftp)\n[![Javadoc](https://img.shields.io/badge/javadoc-1.1-brightgreen.svg?)](https://javadoc.io/doc/com.ajaxjs/aj-ftp)\n[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/lightweight-component/aj-ftp)\n[![License](https://img.shields.io/badge/license-Apache--2.0-green.svg?longCache=true\u0026style=flat)](http://www.apache.org/licenses/LICENSE-2.0.txt)\n[![Email](https://img.shields.io/badge/Contact--me-Email-orange.svg)](mailto:frank@ajaxjs.com)\n\n\n# A Lightweight FTP Client\n\nThis is a simple and lightweight FTP component with the following features:\n\n- Simple \u0026 Lightweight: Easy to use and minimal in size.\n- Based on JDK's `sun.*` extension package: Most standard JDK distributions already include built-in FTP capabilities. However, some environments (such as Android) do not support the `sun.*` packages — that's where this component comes in handy.\n- Supports Progress Tracking: Adds the ability to monitor upload/download progress.\n\n## Source code\n\n[Github](https://github.com/lightweight-component/aj-ftp) | [Gitcode](https://gitcode.com/lightweight-component/aj-ftp)\n\n\n## Usage\n\nRequires Java8+.\n\n### Install\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.ajaxjs\u003c/groupId\u003e\n    \u003cartifactId\u003eaj-ftp\u003c/artifactId\u003e\n    \u003cversion\u003e1.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\nExamples of uploading and downloading files via FTP are shown below. The server `speedtest.tele2.net` is a publicly available, free, and anonymous FTP service found online.\n\n\n```java\npublic class TestFTP {\n    @Test\n    public void testUpload() throws IOException {\n        UploadFtp client = new UploadFtp(\"speedtest.tele2.net\", 21);\n        client.login(\"anonymous\", \"anonymous\");\n        client.upload(\"c:\\\\temp\\\\re.zip\", \"/upload/re.zip\");\n        client.closeServer();\n    }\n\n    @Test\n    public void testDownload() throws IOException {\n        UploadFtp ftp = new UploadFtp(\"speedtest.tele2.net\", 21);\n        ftp.login(\"anonymous\", \"anonymous\");\n        ftp.getFile(\"/1KB.zip\", \"c:\\\\temp\\\\re.zip\");\n    }\n}\n```\n\n## Key Source Code\n\nThe main class is `UploadFtp`, which extends the base `FtpClient` class and is used to implement FTP file upload and download functionality.\n\n\n\n```java\npackage com.ajaxjs.net.ftp;\n\nimport com.ajaxjs.net.ftp.sun.TelnetInputStream;\nimport com.ajaxjs.net.ftp.sun.TelnetOutputStream;\nimport com.ajaxjs.net.ftp.sun.ftp.FtpClient;\n\nimport java.io.*;\nimport java.nio.file.Files;\n\n/**\n * FTP 文件上传\n */\npublic class UploadFtp extends FtpClient {\n    public UploadFtp(String server, int port) throws IOException {\n        super(server, port);\n    }\n\n    /**\n     * 用书上传本地文件到 FTP 服务器上\n     *\n     * @param source 上传文件的本地路径\n     * @param target 上传到 FTP 的文件路径\n     */\n    public void upload(String source, String target) {\n        try {\n            binary();\n\n            try (TelnetOutputStream ftp = put(target);\n                 InputStream file = Files.newInputStream(new File(source).toPath())) {\n                BufferedInputStream in = new BufferedInputStream(file);\n\n                new ProgressListener().copy(in, new BufferedOutputStream(ftp), in.available());\n\n                System.out.print(\"put file suc from \" + source + \"   to  \" + target + \"\\r\\n\");\n            }\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n\n    /**\n     * 从 FTP 上下载所需要的文件\n     *\n     * @param source 在 FTP 上路径及文件名\n     * @param target 要保存的本地的路径\n     */\n    public void getFile(String source, String target) {\n        try {\n            binary();\n\n            try (TelnetInputStream ftp = get(source);\n                 OutputStream file = Files.newOutputStream(new File(target).toPath())) {\n\n                ProgressListener listener = new ProgressListener();\n                listener.setFileName(target);\n                listener.copy(new BufferedInputStream(ftp), new BufferedOutputStream(file), getFileSize(source, ftp));\n\n                System.out.print(\"get file suc from \" + source + \"   to  \" + target + \"\\r\\n\");\n            }\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n\n    /**\n     * 为了计算下载速度和百分比，读取 FTP 该文件的大小\n     */\n    private int getFileSize(String source, TelnetInputStream ftp) throws IOException {\n        // 这里的组合使用是必须得 sendServer 后到 readServerResponse\n        sendServer(\"SIZE \" + source + \"\\r\\n\");\n\n        if (readServerResponse() == 213) {\n            String msg = getResponseString();\n\n            try {\n                return Integer.parseInt(msg.substring(3).trim());\n            } catch (Exception e) {\n            }\n        }\n\n        return 0;\n    }\n}\n```\n\nTutorial(Chinese): https://blog.csdn.net/zhangxin09/article/details/134222511.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flightweight-component%2Faj-ftp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flightweight-component%2Faj-ftp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flightweight-component%2Faj-ftp/lists"}