{"id":16547019,"url":"https://github.com/stefanbirkner/fake-sftp-server-rule","last_synced_at":"2025-03-16T19:32:40.469Z","repository":{"id":45946480,"uuid":"50951192","full_name":"stefanbirkner/fake-sftp-server-rule","owner":"stefanbirkner","description":"A JUnit rule that runs an in-memory SFTP server.","archived":false,"fork":false,"pushed_at":"2023-04-25T13:33:15.000Z","size":88,"stargazers_count":40,"open_issues_count":18,"forks_count":26,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-12T19:13:20.022Z","etag":null,"topics":["inmemory","java","junit-rule","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}},"created_at":"2016-02-02T20:54:42.000Z","updated_at":"2024-01-13T23:54:52.000Z","dependencies_parsed_at":"2022-09-26T21:50:15.330Z","dependency_job_id":null,"html_url":"https://github.com/stefanbirkner/fake-sftp-server-rule","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanbirkner%2Ffake-sftp-server-rule","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanbirkner%2Ffake-sftp-server-rule/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanbirkner%2Ffake-sftp-server-rule/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanbirkner%2Ffake-sftp-server-rule/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stefanbirkner","download_url":"https://codeload.github.com/stefanbirkner/fake-sftp-server-rule/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221667532,"owners_count":16860621,"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","junit-rule","sftp","sftp-server","test","unittest"],"created_at":"2024-10-11T19:13:21.234Z","updated_at":"2024-10-27T11:11:02.940Z","avatar_url":"https://github.com/stefanbirkner.png","language":"Java","funding_links":[],"categories":["测试"],"sub_categories":["语音合成"],"readme":"# Fake SFTP Server Rule\n\n[![Build Status](https://travis-ci.org/stefanbirkner/fake-sftp-server-rule.svg?branch=master)](https://travis-ci.org/stefanbirkner/fake-sftp-server-rule)\n\nFake SFTP Server Rule is a JUnit rule that runs an in-memory SFTP server while\nyour tests are running. 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.\nPlease\n[open an issue](https://github.com/stefanbirkner/fake-sftp-server-rule/issues/new)\nif you want to use it with an older version of Java.\n\nI want to thank my former team SAM at ThoughtWorks for using this library and\n@crizzis, @OArtyomov and @TheSentinel454 for their feature requests.\n\nThere is an alternative to Fake SFTP Server Rule that is independent of the\ntest framework. Its name is\n[Fake SFTP Server Lambda](https://github.com/stefanbirkner/fake-sftp-server-lambda).\n\n## Installation\n\nFake SFTP Server Rule is available from\n[Maven Central](https://search.maven.org/#search|ga|1|fake-sftp-server-rule).\n\n    \u003cdependency\u003e\n      \u003cgroupId\u003ecom.github.stefanbirkner\u003c/groupId\u003e\n      \u003cartifactId\u003efake-sftp-server-rule\u003c/artifactId\u003e\n      \u003cversion\u003e2.0.1\u003c/version\u003e\n    \u003c/dependency\u003e\n\nIf you upgrade from a version \u003c 2.x to the newest version please read the last\nsection of this readme.\n\n## Usage\n\nThe Fake SFTP Server Rule is used by adding it to your test class.\n\n    import com.github.stefanbirkner.fakesftpserver.rule.FakeSftpServerRule;\n\n    public class TestClass {\n      @Rule\n      public final FakeSftpServerRule sftpServer = new FakeSftpServerRule();\n\n      ...\n    }\n\nThis rule starts a server before your test and stops it afterwards.\n\nBy default the SFTP server listens on an auto-allocated port. During the test\nthis port can be obtained by `sftpServer.getPort()`. It can be changed\nby calling `setPort(int)`. If you do this from within a test then the server\ngets restarted. The time-consuming restart can be avoided by setting the port\nimmediately after creating the rule.\n\n    public class TestClass {\n      @Rule\n      public final FakeSftpServerRule sftpServer = new FakeSftpServerRule()\n          .setPort(1234);\n\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    public class TestClass {\n      @Rule\n      public final FakeSftpServerRule sftpServer = new FakeSftpServerRule()\n          .addUser(\"username\", \"password\");\n\n      ...\n    }\n\nIt is also possible to do this during the test using the same method.\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. Fake SFTP Server Rule provides a shortcut for\nuploading files to the server.\n\n    @Test\n    public void testTextFile() {\n      sftpServer.putFile(\"/directory/file.txt\", \"content of file\", UTF_8);\n      //code that downloads the file\n    }\n\n    @Test\n    public void testBinaryFile() {\n      byte[] content = createContent();\n      sftpServer.putFile(\"/directory/file.bin\", content);\n      //code that downloads the file\n    }\n\nTest data that is provided as an input stream can be uploaded 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() {\n      InputStream is = getClass().getResourceAsStream(\"data.bin\");\n      sftpServer.putFile(\"/directory/file.bin\", is);\n      //code that downloads the file\n    }\n\nIf you need an empty directory then you can use the method\n`createDirectory(String)`.\n\n    @Test\n    public void testDirectory() {\n      sftpServer.createDirectory(\"/a/directory\");\n      //code that reads from or writes to that directory\n    }\n\nYou may create multiple directories at once with `createDirectories(String...)`.\n\n    @Test\n    public void testDirectories() {\n      sftpServer.createDirectories(\n        \"/a/directory\",\n        \"/another/directory\"\n      );\n      //code that reads from or writes to that directories\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. Fake SFTP Server Rule provides a shortcut for getting the file's\ncontent from the server.\n\n    @Test\n    public void testTextFile() {\n      //code that uploads the file\n      String fileContent = sftpServer.getFileContent(\"/directory/file.txt\", UTF_8);\n      ...\n    }\n\n    @Test\n    public void testBinaryFile() {\n      //code that uploads the file\n      byte[] fileContent = sftpServer.getFileContent(\"/directory/file.bin\");\n      ...\n    }\n\n### Testing existence of files\n\nIf you want to check whether a file hast been created or deleted then you can\nverify that it exists or not.\n\n    @Test\n    public void testFile() {\n      //code that uploads or deletes the file\n      boolean exists = sftpServer.existsFile(\"/directory/file.txt\");\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 rule\nitself takes care that every test starts and ends with a clean SFTP server.)\n\n    sftpServer.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 Rule.\n\n* [Write an issue.](https://github.com/stefanbirkner/fake-sftp-server-rule/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 Rule 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 Rule 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-rule-X.X.X`\n\n\n## Upgrading from 0.x.y or 1.x.y to version \u003e= 2\n\nIn older versions the SFTP server listened to port 23454 by default. From\nversion 2 on it selects an arbitrary free port by default. If your tests fail\nafter an upgrade you may consider to restore the old behaviour by immediately\nsetting the old port after creating the rule.\n\n    @Rule\n    public final FakeSftpServerRule sftpServer = new FakeSftpServerRule()\n        .setPort(23454);\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefanbirkner%2Ffake-sftp-server-rule","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefanbirkner%2Ffake-sftp-server-rule","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefanbirkner%2Ffake-sftp-server-rule/lists"}