how to use cURL on specific interface

CLinuxCurl

C Problem Overview


I am developing a code in c, which simply FTPs the files on FTP server by using curl utility, by following this example

now i have one simple thing to do, specify curl to use particular interface (IP) of the server for upload, as other interface of the server is associated with other socket connection.

is there any way to do it?

C Solutions


Solution 1 - C

Seems like curl support --interface option

curl --interface eth0 

Solution 2 - C

For anyone that comes here looking for the same answer, but for wlan0 or whatever the non-default interface is on Raspberry/RPi, you'll need to sudo or run as root.

In my case I was running eth0 and wlan0, but eth0 was my default NIC. Ping worked without sudo, curl didn't have verbose enough logging beyond saying the connection timed out and only worked without sudo on eth0. Traceroute finally led me to my answer when the error said "setsockopt SO_BINDTODEVICE: Operation not permitted"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionmadiha malikView Question on Stackoverflow
Solution 1 - CMrFreezerView Answer on Stackoverflow
Solution 2 - CBrandociousView Answer on Stackoverflow