How to get IP of the client in the upload/download event?

0 votes
asked Jan 15, 2017 by allison (170 points)
edited Jan 15, 2017 by allison

Hi all,

We are planning to set up a SCP server and needs to get the client IP when it uploads/downloads files.

It seems that the upload/download evens of the FileServer do not provide the information of the client IPs. In our environment multi clients from different machines can only share the same user name / password to connect to the server (for management reason).

Any workaround to get the client IP? This is a critical requirement for our usage, any help appreciated.


2 Answers

0 votes
answered Aug 11, 2017 by Lukas Pokorny (126,870 points)
Best answer

Rebex File Server 2017 R4 adds Session property to FileUploaded and FileDownloaded event arguments and it includes the client endpoint, making it very simple to determine the client's IP address:

server.FileUploaded += (sender, e) =>
    // get session's IP address
    IPAddress address = ((IPEndPoint)e.Session.ClientEndPoint).Address;
0 votes
answered Jan 16, 2017 by Lukas Pokorny (126,870 points)
edited Aug 11, 2017 by Lukas Pokorny

Update: This approach is no longer necessary. See the new answer for a simple solution available since Rebex File Server 2017 R4.


The solution proposed in another answer should be suitable for this scenario as well. Please give it a try and let us know if you run into any problems.

To enable SCP in addition to SFTP, you would have to add the following line as well:

server.Bind(22, FileServerProtocol.Scp);
commented Jan 16, 2017 by allison (170 points)
Thanks Lukas. This solution does work and solves our problem.