{"id":21496600,"url":"https://github.com/mlibrary/sftp","last_synced_at":"2025-03-17T12:16:15.778Z","repository":{"id":37577426,"uuid":"499651861","full_name":"mlibrary/sftp","owner":"mlibrary","description":"Lightweight ruby gem that shells out to sftp","archived":false,"fork":false,"pushed_at":"2024-03-27T16:54:37.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-01-23T21:53:31.687Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/mlibrary.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2022-06-03T21:07:02.000Z","updated_at":"2022-06-03T21:07:20.000Z","dependencies_parsed_at":"2024-02-14T22:31:27.669Z","dependency_job_id":"add16d78-ca32-4ef2-bdf1-1f92f5801421","html_url":"https://github.com/mlibrary/sftp","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlibrary%2Fsftp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlibrary%2Fsftp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlibrary%2Fsftp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlibrary%2Fsftp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlibrary","download_url":"https://codeload.github.com/mlibrary/sftp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244031154,"owners_count":20386534,"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":[],"created_at":"2024-11-23T16:17:37.294Z","updated_at":"2025-03-17T12:16:15.749Z","avatar_url":"https://github.com/mlibrary.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SFTP\n\nThis gem wraps shell `sftp` to make working with it in Ruby scripts easier.\n\n## Installation\n\nAdd this line to your application's `Gemfile`:\n\n```ruby\ngem \"sftp\",\n  git: \"https://github.com/mlibrary/sftp\",\n  tag: \"{latest_tag_goes_here}\"\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install sftp\n\n## Usage\n\nBasic configuration:\n```\nrequire \"sftp\"\n\nSFTP.configure do |config|\n  config.user = \"your_sftp_user\"\n  config.host = \"your_sftp_host\"\n  config.key_path = \"path/to/your/ssh/key/file\"\nend\n\nclient = SFTP.client\n```\n\n`SFTP.client.ls` returns an array of path names to files in the SFTP user's directory.\n\n```\nSFTP.client.ls\n# returns [\"file1.txt,\"file2.txt\",\"directory\"]\n\nSFTP.client.ls(\"directory\")\n#returns [\"directory/file3.txt\",\"directory/file4.txt\"]\n```\n\n`SFTP.client.get(path, destination)` downloads the file from `path` on the SFTP server to the `destination` path on the local machine.\n\n```sh\nSFTP.client.get(\"direcotry/file3.txt\", \"./\")\nls .\n\"file3.txt\"\n```\n\n`SFTP.client.get_r(path, destination)` downloads everything (files and/or directories) found at `path` on the SFTP server to the `destination` path on the local machine.\n```sh\nSFTP.client.ls(\"directory\")\n# returns [\"file1.txt\", \"file2.txt\"]\nSFTP.client.get_r(\"directory\", \"./\")\nls .\n# directory\nls directory\n# file1.txt   file2.txt\n```\n\n`SFTP.client.rename(from, to)` renames a file on the SFTP server.\n\n```sh\nSFTP.client.ls\n# returns [\"file1.txt, \"file2.txt\", \"directory\"]\nSFTP.client.rename(\"file1.txt, \"directory/renamed.txt\")\nSFT.client.ls\n# returns [\"file2.txt\", \"directory\"]\nSFTP.client.ls(\"directory\")\n# returns [\"directory/file3.txt\", \"directory/file4.txt\", \"directory/renamed.txt\"]\n```\n\n`SFTP.client.put(path, destination)` sends a file from `path` on the local machine to the `destination` path on the SFTP server.\n\n```sh\nls .\n# \"file1.txt\"\nSFTP.client.put(\"file.txt\", \"directory\")\nSFTP.client.ls(\"directory\")\n# returns [\"file1.txt\"]\n```\n\nIf a failure occurs when an underlying `sftp` command is run, an `SFTP::Error` will be raised.\n\n## Development\n\nClone the repo\n\n```bash\ngit clone git@github.com:mlibrary/sftp.git\ncd sftp\n```\n\nrun the `init.sh` script. This will copy a pre-commit hook for git, build the\ncontainer, and set up ssh keys for development. \n```bash\n./init.sh\n```\nstart containers\n\n```bash\ndocker compose up -d\n```\n\nThe compose.yml has a fileserver service running sftp. The files are in the\n`server/files` directory. \n\nTo try out the gem you can run:\n```bash\ndocker compose run --rm app console\nSFTP.client.ls\n```\n\nThis will load the gem in irb, and connect you to the sftp service in compose.yml\n\n### Troubleshooting\nIf the the `app` service can't connect to the `sftp` service, try restarting by\ndoing:\n```bash\ndocker compose down\ndocker compose up -d\n```\n\nThe ssh keys volume mounted in may not have been properly copied to\n`authorized_keys` in the `fileserver` service, and doing this hard restart will\nget the appropriate ones copied in. \n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at\nhttps://github.com/mlibraray/sftp\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlibrary%2Fsftp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlibrary%2Fsftp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlibrary%2Fsftp/lists"}