Check if command line ftp server is running

Hi there,


I have in my app in the resource folder the pyftpdlib library. A commandline FTP server.

When the server is started how can i check the status of the service-server.


So i hope someone can help me out with some example code to check if my ftp service on port 21 is running.


Thanks

Replies

I have in my app in the resource folder [a] commandline FTP server.

What platform are you targeting?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Sorry about that. It is a macOS 10.13 cocoa application.

What do you mean to check?

  • The process is still running...
  • The process has the FTP ports bound...
  • Connections are accepted on port 21...
  • The process is still responding properly to incoming connections on port 21...

There are such things as firewalls where your ftp process could be running and yet no incoming connections would be allowed.

I use this ftp server only for internal network. It is still work in progress.

I now manually start the server outside the main application. And first i want to check if the process is running.

If it's not running then it should be possible to start the server.

If it's running then I show its status with an image and the internal ip-adress of the computer in a label.


I'm happy to check if the process is still running. I know when the user uses other ftp server software i will have a problem.

I dont know and dont have the knowledge if there is something to check if the client uses a ftp server.


I'm open for suggestions how to approach this.


Don't know how to start the server within the app yet. But that's fase 2.


Thanks in advance

Do you intend to deploy via the Mac App Store?

Oh, and before you go too far down the FTP path, I recommend that you read my On FTP post.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

No I will not deploy this app via the App Store. Because the XPC service its not sandboxed and I will use this application for internal use only.


I know FTP is not the best protocol but Apple removed ftp from High Sierra and from OSX Server so i'm forced to think outside the box.


I need ftp because the printer we use in our company uses the ftp protocol to scan to folder.

I came up with ftpdlib library. All is working manually. I can start manually the service after loggining in. Just got the LaunchDaemon working so after a update or reboot they dont have to call me to start the service.


But what i did is a microsoft solution 😉 and I thought why not create an app. I will learn something and its easy to deploy when there are more servers need this solution.


So I hope you can send my to the right path or if there isnt one I will have to hear that. So that I can think of something else for a solution.


Thanks

Thanks for clarifying your requirements.

Does your printer always look for the FTP server on port 21 (the standard port)? Or can you configure that?

This matters due to permissions. macOS (unlike iOS) continues to require root privileges to bind to low-numbered ports (below 1024). If your printer can only connect to the standard FTP port, you’ll have to bind to that port and thus you will need some sort of privilege escalation. This takes a seemingly simple job (run pyftpdlib from inside your app) and turns it into a hard one.

Moreover, it represents a conceptual problem. If there’s a single resource on the system (the FTP port) then their needs to be a single entity responsible for managing it. That means that you really want your FTP server managed by a daemon. If you try to manage it from an app, there’s the possibility that two users on the system might collide.

Thus the architecture I recommend is that you have a launchd daemon that manages your FTP server and you communicate with that daemon to get the server status, start the server, stop the server, and so on. That further breaks down as follows:

  • You need something to install the daemon. It sounds like you’re in a managed environment, in which case it might be best to push an installer package to the machine to install the daemon. It’s certainly easy to do that. In a consumer-oriented app you might want to use

    SMJobBless
    to install the daemon, which is a complex exercise.
  • You need a way to communicate between the daemon and the app. For this I recommend

    NSXPCConnection
    .
  • You need to consider authorisation. The daemon runs as root, so it will be able to do the things it needs to do. How should it react, say, when a user tries to do some destructive action, like stop the server? Is any use allowed to do this? Or is that restricted to some specific users? One way to handle this authorisation is via the Authorisation Services API.

*phew*

A good place to start here is the EvenBetterAuthorizationSample sample code. It does the whole

SMJobBless
thing, which you might want to avoid. But it also shows both
NSXPCConnection
and Authorisation Services, which you will definitely want to look at.

Finally, I want to clarify one thing. You may actually want to use two daemons here:

  • A launchd daemon you write, that speaks over

    NSXPCConnection
    and can be used to start and stop the FTP server.
  • A separate launchd daemon that represents the FTP server itself.

There are other ways to structure this (for example, you could have your daemon launch the FTP server as a child process) but, due to the nature of how launchd works, separating them out might be best.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"