{"id":15101705,"url":"https://github.com/livinginthepast/fake_ftp","last_synced_at":"2025-09-26T22:31:53.410Z","repository":{"id":54222774,"uuid":"1380819","full_name":"livinginthepast/fake_ftp","owner":"livinginthepast","description":"A fake FTP server for use with ruby tests","archived":true,"fork":false,"pushed_at":"2021-03-02T18:01:26.000Z","size":266,"stargazers_count":79,"open_issues_count":7,"forks_count":51,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-17T02:58:26.137Z","etag":null,"topics":["ftp","ftp-server","minitest","rspec","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/livinginthepast.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-02-18T02:03:54.000Z","updated_at":"2023-01-28T10:18:29.000Z","dependencies_parsed_at":"2022-08-13T09:31:03.674Z","dependency_job_id":null,"html_url":"https://github.com/livinginthepast/fake_ftp","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livinginthepast%2Ffake_ftp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livinginthepast%2Ffake_ftp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livinginthepast%2Ffake_ftp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livinginthepast%2Ffake_ftp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/livinginthepast","download_url":"https://codeload.github.com/livinginthepast/fake_ftp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234356547,"owners_count":18819383,"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-server","minitest","rspec","ruby"],"created_at":"2024-09-25T18:28:44.120Z","updated_at":"2025-09-26T22:31:48.123Z","avatar_url":"https://github.com/livinginthepast.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FakeFtp\n\n**Archived:** This gem was written for a specific need that I had at the time. I no longer actively\nwork in Ruby professionally, and avoid FTP as a protocol when possible. Please consider using\nalternatives to this gem if possible.\n\n[![Build status](https://api.travis-ci.org/livinginthepast/fake_ftp.svg?branch=master)](http://travis-ci.org/livinginthepast/fake_ftp)\n[![Code Climate](https://codeclimate.com/github/livinginthepast/fake_ftp/badges/gpa.svg)](https://codeclimate.com/github/livinginthepast/fake_ftp)\n[![Test Coverage](https://codeclimate.com/github/livinginthepast/fake_ftp/badges/coverage.svg)](https://codeclimate.com/github/livinginthepast/fake_ftp/coverage)\n[![Gem Version](https://badge.fury.io/rb/fake_ftp.svg)](https://badge.fury.io/rb/fake_ftp)\n\nThis is a gem that allows you to test FTP implementations in ruby. It is a\nminimal single-client FTP server that can be bound to any arbitrary port on\nlocalhost.\n\n## Why?\n\nWe want to ensure that our code works, in a way that is agnostic to the\nimplementation used (unlike with stubs or mocks).\n\n## How\n\nFakeFtp is a simple FTP server that fakes out enough of the protocol to get us\nby, allowing us to test that files get to their intended destination rather than\ntesting how our code does so.\n\n## Usage\n\nTo test passive upload:\n``` ruby\nrequire 'fake_ftp'\nrequire 'net/ftp'\n\nserver = FakeFtp::Server.new(21212, 21213)\n## 21212 is the control port, which is used by FTP for the primary connection\n## 21213 is the data port, used in FTP passive mode to send file contents\nserver.start\n\nftp = Net::FTP.new\nftp.connect('127.0.0.1', 21212)\nftp.login('user', 'password')\nftp.passive = true\nftp.put('some_file.txt')\nftp.close\n\nexpect(server.files).to include('some_file.txt')\nexpect(server.file('some_file.txt').bytes).to eq 25\nexpect(server.file('some_file.txt')).to be_passive\nexpect(server.file('some_file.txt')).to_not be_active\n\nserver.stop\n```\n\nTo test active upload:\n``` ruby\nserver = FakeFtp::Server.new(21212)\n## 21212 is the control port, which is used by FTP for the primary connection\n## 21213 is the data port, used in FTP passive mode to send file contents\nserver.start\n\nftp = Net::FTP.new\nftp.connect('127.0.0.1', 21212)\nftp.login('user', 'password')\nftp.passive = false\nftp.put('some_file.txt')\nftp.close\n\nexpect(server.files).to include('some_file.txt')\nexpect(server.file('some_file.txt').bytes).to eq 25\nexpect(server.file('some_file.txt')).to be_active\nexpect(server.file('some_file.txt')).to_not be_passive\n\nserver.stop\n```\n\nNote that many FTP clients default to active, unless specified otherwise.\n\n## Caveats\n\nThis is *not* a real FTP server and should not be treated as one. The goal of\nthis gem is not to create a thread-safe multi-client implementation.  It is best\nused to unit test code that generates files and transfers them to an FTP server.\n\nAs such, there are some things that won't be accepted upstream from pull\nrequests:\n* simultaneous multi-client code\n* persistence support\n* binding to arbitrary IPs\n* global state beyond that required to pass the minimum required to\n  generate passing tests\n\n## Recommendations for testing patterns\n\n*Separate configuration from code.* Do not hard code the IP address, FQDN or\nport of an FTP server in your code. It introduces fragility into your tests.\nAlso, the default FTP port of 21 is a privileged port, and should be avoided.\n\n*Separate the code that generates files from the code that uploads files.* You\ntests will run much more quickly if you only try to upload small files. If you\nhave tests showing that you generate correct files from your data, then you can\ntrust that. Why do you need to upload a 20M file in your tests if you can stub\nout your file generation method and test file upload against 10 bytes? Fast fast\nfast.\n\n## References\n\n* http://rubyforge.org/projects/ftpd/ - a simple ftp daemon written by Chris Wanstrath\n* http://ruby-doc.org/stdlib/libdoc/gserver/rdoc/index.html - a generic server in the Ruby standard library, by John W Small\n\n## Alternatives\n\n* https://github.com/thejamespinto/ftpmock - Test your FTP calls offline.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flivinginthepast%2Ffake_ftp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flivinginthepast%2Ffake_ftp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flivinginthepast%2Ffake_ftp/lists"}