{"id":16547027,"url":"https://github.com/stefanbirkner/fake-sftp-server-lambda","last_synced_at":"2025-03-21T10:31:45.270Z","repository":{"id":43980615,"uuid":"77838380","full_name":"stefanbirkner/fake-sftp-server-lambda","owner":"stefanbirkner","description":"Runs an in-memory SFTP server while your tests are running.","archived":false,"fork":false,"pushed_at":"2024-10-03T18:51:25.000Z","size":94,"stargazers_count":23,"open_issues_count":9,"forks_count":10,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-01T05:13:50.724Z","etag":null,"topics":["inmemory","java","sftp","sftp-server","test","unittest"],"latest_commit_sha":null,"homepage":"","language":"Java","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/stefanbirkner.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}},"created_at":"2017-01-02T14:17:08.000Z","updated_at":"2024-11-06T11:18:29.000Z","dependencies_parsed_at":"2024-10-28T10:17:55.299Z","dependency_job_id":null,"html_url":"https://github.com/stefanbirkner/fake-sftp-server-lambda","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanbirkner%2Ffake-sftp-server-lambda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanbirkner%2Ffake-sftp-server-lambda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanbirkner%2Ffake-sftp-server-lambda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanbirkner%2Ffake-sftp-server-lambda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stefanbirkner","download_url":"https://codeload.github.com/stefanbirkner/fake-sftp-server-lambda/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244130280,"owners_count":20402756,"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":["inmemory","java","sftp","sftp-server","test","unittest"],"created_at":"2024-10-11T19:13:22.515Z","updated_at":"2025-03-21T10:31:44.935Z","avatar_url":"https://github.com/stefanbirkner.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fake SFTP Server Lambda\n\n[![Build Status](https://travis-ci.org/stefanbirkner/fake-sftp-server-lambda.svg?branch=master)](https://travis-ci.org/stefanbirkner/fake-sftp-server-lambda)\n\nFake SFTP Server Lambda runs an in-memory SFTP server while your tests are\nrunning. It uses the SFTP server of the\n[Apache SSHD](http://mina.apache.org/sshd-project/index.html) project.\n\nFake SFTP Server Rule is published under the\n[MIT license](http://opensource.org/licenses/MIT). It requires at least Java 8.\n\nFor JUnit 4 there is an alternative to Fake SFTP Server Lambda. Its name is\n[Fake SFTP Server Rule](https://github.com/stefanbirkner/fake-sftp-server-rule).\n\n\n## Installation\n\nFake SFTP Server Lambda is available from\n[Maven Central](https://search.maven.org/#search|ga|1|fake-sftp-server-lambda).\n\nFake SFTP Server Lambda uses the SFTP server of the Apache SSHD project. The API\nof the server changed in version 2.6.0 in a way that required changes in Fake\nSFTP Server Lambda. Therefore, there are two lines of development. As long as\nyour project does not depend on an older version of Apache SSHD you should use\nFake SFTP Server Lambda 2.0.0 which is compatible with Apache SSHD 2.6.0 and\nlater.\n\n    \u003cdependency\u003e\n      \u003cgroupId\u003ecom.github.stefanbirkner\u003c/groupId\u003e\n      \u003cartifactId\u003efake-sftp-server-lambda\u003c/artifactId\u003e\n      \u003cversion\u003e2.0.0\u003c/version\u003e\n      \u003cscope\u003etest\u003c/scope\u003e\n    \u003c/dependency\u003e\n\nUsers whose projects have a dependency to Apache SSHD with a version before 2.6.0\nmust use Fake SFTP Server Lambda 1.0.1.\n\n    \u003cdependency\u003e\n      \u003cgroupId\u003ecom.github.stefanbirkner\u003c/groupId\u003e\n      \u003cartifactId\u003efake-sftp-server-lambda\u003c/artifactId\u003e\n      \u003cversion\u003e1.0.1\u003c/version\u003e\n      \u003cscope\u003etest\u003c/scope\u003e\n    \u003c/dependency\u003e\n\n\n## Usage\n\nFake SFTP Server Lambda is used by wrapping your test code with the method\n`withSftpServer`.\n\n    import static com.github.stefanbirkner.fakesftpserver.lambda.FakeSftpServer.withSftpServer;\n\n    public class TestClass {\n      @Test\n      public void someTest() throws Exception {\n        withSftpServer(server -\u003e {\n          //test code\n        });\n      }\n    }\n\n`withSftpServer` starts an SFTP server before executing the test code and shuts\ndown the server afterwards. The test code uses the provided server object to\nobtain information about the running server or use additional features of Fake\nSFTP Server Lambda.\n\nBy default the SFTP server listens on an auto-allocated port. During the test\nthis port can be obtained by `server.getPort()`. It can be changed by calling\n`setPort(int)`. The server is restarted whenever this method is called.\n\n    withSftpServer(server -\u003e {\n      server.setPort(1234);\n      ...\n    });\n\nYou can interact with the SFTP server by using the SFTP protocol with password\nauthentication. By default the server accepts every pair of username and\npassword, but you can restrict it to specific pairs.\n\n    withSftpServer(server -\u003e {\n      server.addUser(\"username\", \"password\");\n      ...\n    });\n\n\n### Testing code that reads files\n\nIf you test code that reads files from an SFTP server then you need a server\nthat provides these files. The server object has a shortcut for putting files\nto the server.\n\n    @Test\n    public void testTextFile() throws Exception {\n      withSftpServer(server -\u003e {\n        server.putFile(\"/directory/file.txt\", \"content of file\", UTF_8);\n        //code that reads the file using the SFTP protocol\n      });\n    }\n\n    @Test\n    public void testBinaryFile() throws Exception {\n      withSftpServer(server -\u003e {\n        byte[] content = createContent();\n        server.putFile(\"/directory/file.bin\", content);\n        //code that reads the file using the SFTP protocol\n      });\n    }\n\nTest data that is provided as an input stream can be put directly from that\ninput stream. This is very handy if your test data is available as a resource.\n\n    @Test\n    public void testFileFromInputStream() throws Exception {\n      withSftpServer(server -\u003e {\n        InputStream is = getClass().getResourceAsStream(\"data.bin\");\n        server.putFile(\"/directory/file.bin\", is);\n        //code that reads the file using the SFTP protocol\n      });\n    }\n\nIf you need an empty directory then you can use the method\n`createDirectory(String)`.\n\n    @Test\n    public void testDirectory() throws Exception {\n      withSftpServer(server -\u003e {\n        server.createDirectory(\"/a/directory\");\n        //code that reads from or writes to that directory\n      });\n    }\n\nYou may create multiple directories at once with `createDirectories(String...)`.\n\n    @Test\n    public void testDirectories() throws Exception {\n      withSftpServer(server -\u003e {\n        server.createDirectories(\n          \"/a/directory\",\n          \"/another/directory\"\n        );\n        //code that reads from or writes to that directories\n      });\n    }\n\n\n### Testing code that writes files\n\nIf you test code that writes files to an SFTP server then you need to verify\nthe upload. The server object provides a shortcut for getting the file's\ncontent from the server.\n\n    @Test\n    public void testTextFile() throws Exception {\n      withSftpServer(server -\u003e {\n        //code that uploads the file using the SFTP protocol\n        String fileContent = server.getFileContent(\"/directory/file.txt\", UTF_8);\n        //verify file content\n      });\n    }\n\n    @Test\n    public void testBinaryFile() throws Exception {\n      withSftpServer(server -\u003e {\n        //code that uploads the file using the SFTP protocol\n        byte[] fileContent = server.getFileContent(\"/directory/file.bin\");\n        //verify file content\n      });\n    }\n\n### Testing existence of files\n\nIf you want to check whether a file was created or deleted then you can verify\nthat it exists or not.\n\n    @Test\n    public void testFile() throws Exception {\n      withSftpServer(server -\u003e {\n        //code that uploads or deletes the file\n        boolean exists = server.existsFile(\"/directory/file.txt\");\n        //check value of exists variable\n      });\n    }\n\nThe method returns `true` iff the file exists and it is not a directory.\n\n### Delete all files\n\nIf you want to reuse the SFTP server then you can delete all files and\ndirectories on the SFTP server. (This is rarely necessary because the method\n`withSftpServer` takes care that it starts and ends with a clean SFTP server.)\n\n    server.deleteAllFilesAndDirectories()\n\n## Contributing\n\nYou have three options if you have a feature request, found a bug or\nsimply have a question about Fake SFTP Server Lambda.\n\n* [Write an issue.](https://github.com/stefanbirkner/fake-sftp-server-lambda/issues/new)\n* Create a pull request. (See [Understanding the GitHub Flow](https://guides.github.com/introduction/flow/index.html))\n* [Write a mail to mail@stefan-birkner.de](mailto:mail@stefan-birkner.de)\n\n\n## Development Guide\n\nFake SFTP Server Lambda is build with [Maven](http://maven.apache.org/). If you\nwant to contribute code then\n\n* Please write a test for your change.\n* Ensure that you didn't break the build by running `mvn verify -Dgpg.skip`.\n* Fork the repo and create a pull request. (See [Understanding the GitHub Flow](https://guides.github.com/introduction/flow/index.html))\n\nThe basic coding style is described in the\n[EditorConfig](http://editorconfig.org/) file `.editorconfig`.\n\nFake SFTP Server Lambda supports [Travis CI](https://travis-ci.org/) for\ncontinuous integration. Your pull request will be automatically build by Travis\nCI.\n\n\n## Release Guide\n\n* Select a new version according to the\n  [Semantic Versioning 2.0.0 Standard](http://semver.org/).\n* Set the new version in `pom.xml` and in the `Installation` section of\n  this readme.\n* Commit the modified `pom.xml` and `README.md`.\n* Run `mvn clean deploy` with JDK 8.\n* Add a tag for the release: `git tag fake-sftp-server-lambda-X.X.X`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefanbirkner%2Ffake-sftp-server-lambda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefanbirkner%2Ffake-sftp-server-lambda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefanbirkner%2Ffake-sftp-server-lambda/lists"}