{"id":13801611,"url":"https://github.com/SpotlightKid/micropython-ftplib","last_synced_at":"2025-05-13T11:31:26.163Z","repository":{"id":49753275,"uuid":"79956479","full_name":"SpotlightKid/micropython-ftplib","owner":"SpotlightKid","description":"An FTP client library for MicroPython.","archived":false,"fork":false,"pushed_at":"2025-05-03T13:24:21.000Z","size":134,"stargazers_count":37,"open_issues_count":1,"forks_count":17,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-03T14:29:26.723Z","etag":null,"topics":["ftp","ftp-client","ftplib","micropython","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SpotlightKid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2017-01-24T21:31:35.000Z","updated_at":"2025-05-03T13:24:24.000Z","dependencies_parsed_at":"2024-03-08T08:30:05.603Z","dependency_job_id":"fab3fea2-5e25-4b84-98ad-d52c36bf25f7","html_url":"https://github.com/SpotlightKid/micropython-ftplib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpotlightKid%2Fmicropython-ftplib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpotlightKid%2Fmicropython-ftplib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpotlightKid%2Fmicropython-ftplib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpotlightKid%2Fmicropython-ftplib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SpotlightKid","download_url":"https://codeload.github.com/SpotlightKid/micropython-ftplib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253932892,"owners_count":21986473,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","ftplib","micropython","python"],"created_at":"2024-08-04T00:01:24.946Z","updated_at":"2025-05-13T11:31:26.154Z","avatar_url":"https://github.com/SpotlightKid.png","language":"Python","readme":"# micropython-ftplib\n\nAn FTP client library for MicroPython.\n\nThis is an adaption of the [ftplib] module from the CPython standard library to\nMicroPython. Apart from making it compatible with the `socket` module\nimplementation of MicroPython and removing the use of the `re` library, some\nparts of the original library have been removed and the code and docstrings\nhave been cleaned up somewhat.\n\nThe `FTP_TLS` class has been moved to a separate module file (`ftplibtls.py`)\nand the `all_errors` module global variable has been removed. The test code has\nbeen moved to a separate script and reworked too. The `ftpcp` function has been\nmoved to the `ftpcp.py` module file.\n\nThe code has been tested under the following MicroPython ports against the FTP\nserver from the [pyftpdlib] package.\n\n* `unix`\n* `stm32` (using W5500 ethernet module)\n* `esp8266`\n* `esp32`\n* `rp2` (Raspberry Pi Pico W)\n\nFor the `esp8266` port the code needed to be slighty altered to make it work\nwith the `ssl` module there and to reduce the memory usage. This version can\nbe found in the [esp](./esp) directory (this version also works with the\n`esp32` port, but there you should be able to use the normal version too).\n\n\n## FTP over TLS\n\nFTP-over-TLS support is available in a separate `ftplibtls` module:\n\n```py\n\u003e\u003e\u003e from ftplibtls import FTP_TLS\n\u003e\u003e\u003e ftp = FTP_TLS('example.com')  # default port 21\n\u003e\u003e\u003e ftp.login('username', 'password')\n\u003e\u003e\u003e ftp.prot_p()\n\u003e\u003e\u003e ftp.retrlines('LIST')\n```\n\nNote that you must call the `prot_b` method after connecting and\nauthentication to actually establish secure communication for data transfers.\n\nIf you require server certificate validation (recommended):\n\n```py\n\u003e\u003e\u003e from ftplib import FTP_TLS, ssl\n\u003e\u003e\u003e ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)\n\u003e\u003e\u003e ctx.verify_mode = ssl.CERT_REQUIRED\n\u003e\u003e\u003e ctx.load_verify_locations(cafile=\"cert.der\")  # Certificate file must be in DER format\n\u003e\u003e\u003e ftp = FTP_TLS(ssl_context=ctx, server_hostname=\"example.com\")\n\u003e\u003e\u003e ftp.connect('example.com')\n\u003e\u003e\u003e ftp.prot_p()\n\u003e\u003e\u003e ftp.retrlines('LIST')\n```\n\nUse the `server_hostname` constructor argument if the common name in the\nserver's certificate differs from the host name used for connecting.\n\nNote: the version of `ftplibtls` in the `esp` directory does not support the\n`ssl_context` and `server_hostname` constructor arguments, since the `ssl`\nmodule of the `esp2866` port unfortunately does not support server certificate\nvalidation.\n\n\n### Testing FTP over TLS\n\nThe `tests` directory contains the `pyftplib-server.py` script to start an FTP\nserver, which is based on the [pyftpdlib] library for CPython and which\nsupports FTP over TLS.\n\nTo run this script with TLS support enabled, you first need to create a server\ncertificate. For testing, a self-signed certificate can be used and created\nwith:\n\n```con\nopenssl req -new -x509 -nodes -out tests/cert.pem -keyout tests/key.pem\n```\n\nSpecify the country, code, location, organization and common name, when\nprompted. (Note: the test scripts in the `tests` directory assume that the\ncommon name you choose is `example.com`. If you choose a different common name,\nthese scripts will fail with an error due to certificate verification failure.)\n\nCombine the server certificate and the key into one file:\n\n```con\ncat tests/key.pem tests/cert.pem \u003e tests/keycert.pem\n```\n\nThe `ftplibtls` module needs the server certificate in DER format, so convert\nit with:\n\n```con\nopenssl x509 -in tests/cert.pem -out tests/cert.der -outform DER\n```\n\nNow you can start the test FTP server:\n\n```con\nmkdir -p tests/ftproot\npython3 tests/pyftpdlib-server.py -w -s -p 2121 -c tests/keycert.pem tests/ftproot\n```\n\nThe FTP server will listen on port 2121, support TLS using the certificate in the\nfile `tests/keycert.pem` and allow clients to read files from the directory\n`tests/ftproot` and also upload files there.\n\nTo upload a file to the test FTP server using the `ftplibtls` module, run the\n`tests/test_upload.py` script:\n\n```con\nMICROPYPATH=`pwd` micropython tests/test_upload.py ftps://localhost:2121 \u003cfilename\u003e\n```\n\nThis should upload the file `\u003cfilename\u003e` to the FTP server using FTP over TLS\nand the file should appear in the `tests/ftproot` directory.\n\n\n[ftplib]: https://docs.python.org/3/library/ftplib.html\n[pyftpdlib]: https://github.com/giampaolo/pyftpdlib/\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Communications"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSpotlightKid%2Fmicropython-ftplib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSpotlightKid%2Fmicropython-ftplib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSpotlightKid%2Fmicropython-ftplib/lists"}