My teacher asked me to do a program using execlp that will do the same as :
scp * mylogin@mycomputer:/home/mylogin/myfolder
I’ve tried :
execlp("scp", "scp", "*", "mylogin@mycomputer:/home/mylogin/myfolder", 0)
I found out that it doesn’t work since it’s the shell that convert * to files name.
Is there a way that I could do it, I don’t really know how I could get all the files names into the execlp call?
I’m sorry if i’m not clear, it’s just hard for me to explain 🙁 but I’m really looking for any tips on how the “*” works it would be great 🙂
You can use
glob(3)to perform the glob match. Then allocate an array where you put the matching filenames and the other arguments to scp. You will not want to useexeclp()butexecvp()in this case as you now have an array instead of an argument list.However, the assignment by itself is rather stupid: If you want shell wildcard expansion, use
system()which executes the given command in a shell (with all its advantages and disadvantages).