0

I'm developing a firmware updater that should download data from a web server and upload it to an Embedded Linux device.

I want a program (client) to start another program (server) before establishing a connection between them and start sending the data. To do that in the same environment is easy: just call QProcess and startDetached(), but I want to do that remotely: I want to start the client in the Desktop machine and, with the device connected via ETH/TCP in a known IP address, click a button which will ask the device to start the server. When the server finishes starting and start waiting for connections, the Desktop app will then open the socket connection and start sending the data. After all data have being send, another command should be send to ask the server to shut down, closing the connection and finishing the file transfer operation.

My question is: how can I do this operation of asking for an application to either start or stop when it is located in a different machine (in an Embedded Linux device while the caller is in a PC)? Notice that the solution must be such that doesn't depend on some extra software (such as a Tcp server) to constantly run on the device - that's precisely what I'm trying to avoid.

Momergil
  • 2,213
  • 5
  • 29
  • 59

1 Answers1

1

This is not related to Qt in any way, because it doesn't provides anything for that purpose. There are at least two paths from this point:

  • use SSH from your application to start any process in the remote machine: ssh user@remote-machine "any command here". This can be called using QProcess; or
  • write another software to listen to socket commands and start/stop any process you want, then get it running all the time in the remote machine. Then, it's just a matter of changing your client software to send the relevant commands

Beware of any security issue that may arise by allowing the machine to execute arbitrary commands from external sources.

Vitor
  • 2,734
  • 29
  • 40
  • well, your second point doesn't make much sense to me: what I want to do is precisely avoid having one extra app running on the device (in case a FTP server): I want to open it only for the time I need to use it. So if your solution depends on the second point (it wasn't clear for me if it does), it doesn't work for me :) – Momergil Apr 09 '15 at 11:59
  • btw, how exactly would be the call to `ssh`? I found some threads on google telling about how to use ssh with QProcess (https://forum.qt.io/topic/3788/qprocess-ssh-write-password/5 / http://stackoverflow.com/questions/20743793/how-to-detect-when-ssh-connection-over-a-qprocess-has-finished / http://www.qtforum.org/article/35299/qprocess-and-ssh.html ) but they weren't clear for me. – Momergil Apr 09 '15 at 12:00
  • 1
    You may use one solution or the other (not both). The best way to use ssh for commands is adding the public key from the user running your local application to the ~/.ssh/authorized_keys of the remote machine. This way, no password will be asked – Vitor Apr 09 '15 at 12:27
  • you may have to use the full path for ssh, for example /usr/bin/ssh. Use `whereis ssh` in your machine to find the exact path for you – Vitor Apr 09 '15 at 12:28
  • thanks for the clarification. I'm trying to implement the first of the two solutions and it's not working. The command I'm trying to use is: `/usr/bin/ssh root@10.1.25.11 "cd /media/mmcblk0p2/bin ./FTPTester&"`. Any suggestions? – Momergil Apr 09 '15 at 13:18
  • I even tried the simpler solutions found here: http://www.cyberciti.biz/faq/unix-linux-execute-command-using-ssh/ but none of those commands are returning anything or doing anything when I call them. – Momergil Apr 09 '15 at 13:22
  • 1
    cd /media/mmcblk0p2/bin ./FTPTester& is not a valid command. I guess you forgot to separate then using a ; or a &&. Try: /usr/bin/ssh root@10.1.25.11 "cd /media/mmcblk0p2/bin && ./FTPTester&". I'd like try first without the &, for simplicity – Vitor Apr 09 '15 at 14:11