{"id":19866150,"url":"https://github.com/tlux/sftp_client","last_synced_at":"2025-04-09T12:09:55.761Z","repository":{"id":50838064,"uuid":"185829114","full_name":"tlux/sftp_client","owner":"tlux","description":"An Elixir SFTP Client that wraps Erlang's ssh and ssh_sftp.","archived":false,"fork":false,"pushed_at":"2024-03-25T21:16:28.000Z","size":274,"stargazers_count":38,"open_issues_count":3,"forks_count":21,"subscribers_count":10,"default_branch":"main","last_synced_at":"2024-03-25T22:29:43.622Z","etag":null,"topics":["elixir","elixir-library","hex-package","sftp","sftp-client","ssh"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tlux.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2019-05-09T15:50:29.000Z","updated_at":"2024-08-05T12:20:26.867Z","dependencies_parsed_at":"2024-02-24T18:22:51.377Z","dependency_job_id":"610b5d23-4bf9-4d2f-bd3d-272662368a81","html_url":"https://github.com/tlux/sftp_client","commit_stats":{"total_commits":160,"total_committers":6,"mean_commits":"26.666666666666668","dds":0.05625000000000002,"last_synced_commit":"5601955012582ccde80cdf5cc09790ec71c6b4db"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlux%2Fsftp_client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlux%2Fsftp_client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlux%2Fsftp_client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlux%2Fsftp_client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tlux","download_url":"https://codeload.github.com/tlux/sftp_client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248036067,"owners_count":21037092,"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":["elixir","elixir-library","hex-package","sftp","sftp-client","ssh"],"created_at":"2024-11-12T15:25:06.464Z","updated_at":"2025-04-09T12:09:55.742Z","avatar_url":"https://github.com/tlux.png","language":"Elixir","readme":"# SFTP Client\n\n[![Build](https://github.com/tlux/sftp_client/actions/workflows/elixir.yml/badge.svg)](https://github.com/tlux/sftp_client/actions/workflows/elixir.yml)\n[![Coverage Status](https://coveralls.io/repos/github/tlux/sftp_client/badge.svg?branch=main)](https://coveralls.io/github/tlux/sftp_client?branch=main)\n[![Module Version](https://img.shields.io/hexpm/v/sftp_client.svg)](https://hex.pm/packages/sftp_client)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/sftp_client/)\n[![Total Download](https://img.shields.io/hexpm/dt/sftp_client.svg)](https://hex.pm/packages/sftp_client)\n[![License](https://img.shields.io/hexpm/l/sftp_client.svg)](https://github.com/tlux/sftp_client/blob/main/LICENSE.md)\n[![Last Updated](https://img.shields.io/github/last-commit/tlux/sftp_client.svg)](https://github.com/tlux/sftp_client/commits/main)\n\nAn Elixir SFTP Client that wraps Erlang's\n[ssh](http://erlang.org/doc/man/ssh.html) and\n[ssh_sftp](http://erlang.org/doc/man/ssh_sftp.html).\n\n## Prerequisites\n\n- Erlang 24 or greater\n- Elixir 1.11 or greater\n\n## Installation\n\nThe package can be installed by adding `:sftp_client` to your list of\ndependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:sftp_client, \"~\u003e 2.1\"}\n  ]\nend\n```\n\n## Usage\n\nThere are bang (!) counterparts for almost all available functions.\n\n### Connect \u0026 Disconnect\n\nTo open a new connection to an SFTP server:\n\n```elixir\n{:ok, conn} = SFTPClient.connect(host: \"ftp.myhost.com\")\n```\n\nDue to a [change in OTP\n24](https://github.com/erlang/otp/commit/59285df73841273adb111996cdb590ae1b86742b)\nthat removed automatic public key lookup in the sftp module you may need to\ndefine the `modify_algorithms` option to avoid \"Key exchange failed\" errors:\n\n```elixir\n{:ok, conn} = SFTPClient.connect(\n  host: \"ftp.myhost.com\",\n  modify_algorithms: [\n    append: [\n      public_key: [:\"ssh-rsa\"]\n    ]\n  ]\n)\n```\n\nRefer to the docs for `SFTPClient.Operations.Connect.connect/1` to find out\nall available options.\n\nIt is strongly recommended to close a connection after your operations have\ncompleted:\n\n```elixir\nSFTPClient.disconnect(conn)\n```\n\nFor short-lived connections you can also use a function as second argument.\nAfter the function body has run or raises, the connection is automatically\nclosed.\n\n```elixir\nSFTPClient.connect([host: \"ftp.myhost.com\"], fn conn -\u003e\n  # Do something with conn\nend)\n```\n\n### Download\n\nTo download a file from the server you can use the following function.\n\n```elixir\nSFTPClient.download_file(conn, \"my/remote/dir/file.jpg\", \"my/dir/local-file.jpg\")\n# =\u003e {:ok, \"my/dir/local-file.jpg\"}\n```\n\nWhen the third argument is an existing directory on your file system, the file\nis downloaded to a file with the same name as the one on the server.\n\n```elixir\nSFTPClient.download_file(conn, \"my/remote/dir/image.png\", \"my/local/dir\")\n# =\u003e {:ok, \"my/local/dir/image.png\"}\n```\n\nIt is also possible to use Streams to download data into a file or memory.\n\n```elixir\nsource_stream = SFTPClient.stream_file!(conn, \"my/remote/file.jpg\")\ntarget_stream = File.stream!(\"my/local/file.jpg\")\n\nsource_stream\n|\u003e Stream.into(target_stream)\n|\u003e Stream.run()\n```\n\n### Upload\n\nTo upload are file from the file system you can use the following function.\n\n```elixir\nSFTPClient.upload_file(conn, \"my/local/dir/file.jpg\", \"my/remote/dir/file.jpg\")\n# =\u003e {:ok, \"my/remote/dir/file.jpg\"}\n```\n\nYou can also use Streams to upload data. Please make sure to set a proper chunk\nsize or the upload may be very slow.\n\n```elixir\nsource_stream = File.stream!(\"my/local/file.jpg\", [], 32_768)\ntarget_stream = SFTPClient.stream_file!(conn, \"my/remote/file.jpg\")\n\nsource_stream\n|\u003e Stream.into(target_stream)\n|\u003e Stream.run()\n```\n\n### List Directory\n\n```elixir\nSFTPClient.list_dir(conn, \"my/dir\")\n# =\u003e {:ok, [\"my/dir/file_1.jpg\", \"my/dir/file_2.jpg\", ...]}\n```\n\n### Create Directory\n\n```elixir\nSFTPClient.make_dir(conn, \"my/new/dir\")\n```\n\nNote that this operation fails unless the parent directory exists.\n\n### Delete\n\nTo delete a file:\n\n```elixir\nSFTPClient.delete_file(conn, \"my/remote/file.jpg\")\n```\n\nTo delete a directory:\n\n```elixir\nSFTPClient.delete_dir(conn, \"my/remote/dir\")\n```\n\nNote that a directory cannot be deleted as long as it still contains files.\n\n### Rename\n\nTo move/rename a file or directory:\n\n```elixir\nSFTPClient.rename(conn, \"my/remote/file.jpg\", \"my/remote/new-file.jpg\")\n```\n\n### File Info\n\nYou can retrieve meta data about a file from the server such as file size,\nmodification time, file permissions, owner and so on.\n\n```elixir\nSFTPClient.file_info(conn, \"my/remote/file.jpg\")\n# =\u003e {:ok, %File.Stat{...}}\n```\n\nRefer to the [`File.Stat`](https://hexdocs.pm/elixir/File.Stat.html) docs for a\nlist of available file information.\n\n### Symbolic Links\n\nThere are also a couple of functions that handle symlinks.\n\nIt is possible to get the target of a symlink.\n\n```elixir\nSFTPClient.read_link(conn, \"my/remote/link.jpg\")\n# =\u003e {:ok, \"my/remote/file.jpg\"}\n```\n\nYou can retrieve meta data about symlinks, similar to `file_info/2`.\n\n```elixir\nSFTPClient.link_info(conn, \"my/remote/link.jpg\")\n# =\u003e {:ok, %File.Stat{...}}\n```\n\nAnd you are able to create symlinks.\n\n```elixir\nSFTPClient.make_link(conn, \"my/remote/link.jpg\", \"my/remote/file.jpg\")\n```\n\n## License\n\nThis library is released under the MIT License. See the [LICENSE.md](./LICENSE.md) file\nfor further details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftlux%2Fsftp_client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftlux%2Fsftp_client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftlux%2Fsftp_client/lists"}