Skip to content
Advertisement

How to read a file from a remote device from C program and Ubuntu OS? [closed]

I am trying to read a file located at remote device, it has Debian OS. My C program is running on Ubuntu with Eclipse. The two devices are linked by USB cable. I can access the remote device using ssh from my console like ssh root@192.168.7.2. Now is I like to have access to a file at root of the remote device from my C program. I tried as FILE *ptr = popen("ssh root@192.168.170.155:/1.jpg", "r");. It doesn’t work. What is the correct way to have file access so that I can read file from my C program? Or is there any better approach for that? Thanks

Advertisement

Answer

I am afraid it’s not as simple as that. The unix file and pipe API are meant for working with local files – ie. files that can be accessed by the instance of OS running. In order to read file on remote machine – that’s accessible via ssh, is considerably more involved. Normally – the choices are

  1. Running an NFS – where remote machine is an NFS server and your machine as NFS client and then you can do normal, open, read, write on your local machine.
  2. Other option is to programmatically implement what ssh or other protocols do. Slightly more involved. So that option is not available.

Depending upon what you want to do with file, there might be a third option – which is running an scp in system function in your c program and then copy the file locally and do whatever you want to do with the file.

These are broadly the options. If you can specifically tell – ‘what you want to do with the file data’, may be there’s another option available.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement