12

I have some code I need to write a test for that connects to a vendor's SFTP server and puts a file there. Right now the test is connecting to their actual server but I'd rather not do that. Ideally I'd like to use a fake, in memory, sever along the lines of MockFtpServer. The I tried using that one and it gets part of the way there but dies at the point of issuing the actual commands since it doesn't recognize them.

The code in question is a flow setup within Mule ESB.

Steven Surowiec
  • 10,030
  • 5
  • 32
  • 37
  • If you can't find one you could always set up a regular one to run from a temp directory. – Rup May 17 '11 at 22:10
  • The solution I came up with was to make the type of the server configurable. So in tests it uses an FTP server and in production an SFTP server. This lets me use a mock, in memory, FTP server for tests. Not perfect but it gets the job done and works on any machine. – Steven Surowiec Jul 11 '11 at 13:37
  • @StevenSurowiec How did you make the type of the server configurable? – Andres Apr 22 '14 at 16:11
  • By current standards, this question is off-topic as it requests to recommend a software library. See [help/on-topic]. – Didier L Feb 13 '18 at 15:42

2 Answers2

3

From Java SFTP server library?: you might be able to use SSHTools (see http://sourceforge.net/projects/sshtools/). They don't provide any good examples but the code base in SVN has some classes that appear to indicate that they support SFTP server commands (see http://sshtools.svn.sourceforge.net/viewvc/sshtools/trunk/j2ssh/src/com/sshtools/daemon/sftp/ and http://sshtools.svn.sourceforge.net/viewvc/sshtools/trunk/j2ssh/src/com/sshtools/j2ssh/sftp/). Some heavy lifting on your part will be necessary.

Let me know if that helps.

Community
  • 1
  • 1
Femi
  • 64,273
  • 8
  • 118
  • 148
2

You can use org.apache.sshd.server, see https://mina.apache.org/sshd-project/index.html.

It's not trivial to configure, but there is an example: https://github.com/ggrandes/sftpserver

Roger Butenuth
  • 546
  • 2
  • 7
  • This is a borderline [link-only answer](//meta.stackexchange.com/q/8231). You should expand your answer to include as much information here, and use the link only for reference. – Blue Feb 13 '18 at 19:42
  • @FrankerZ The question itself is off-topic so we shouldn't hope for good answers. The other answer also suffers from the same issue. – Didier L Feb 13 '18 at 20:49