Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ftp client controlled by pipe in C

Tags:

c

fork

pipe

I am trying to control ftp client from C program (OS X). I did fork and execve - process is started ok. The problem is with pipes - I can send command to ftp client process and get feedback from it just fine (If i send "help\n" i get back help output) but what I never get in pipe is "ftp> " prompt. Any ideas?

Ivan

like image 201
Ivan Ostres Avatar asked Mar 13 '26 01:03

Ivan Ostres


2 Answers

Your ftp client is probably behaving differently if stdin/stdout is a terminal or something else (lots of program do, for a start the C library does buffering in a different way...) If you want to control that, search information about pseudo-terminals, that's a little too technical to be explained here. (And looks first at programs like expect, it's possible you won't have to write yours).

like image 102
AProgrammer Avatar answered Mar 15 '26 22:03

AProgrammer


A program can examine stdin to find out whether it's a terminal or a pipe. In your case, the FTP program probably does that (for example to know whether it can use escape sequences to render progress bars or offer command line editing).

If you really need the prompt, you have to look into PTYs (pseudo terminals) which emulate a console.

like image 22
Aaron Digulla Avatar answered Mar 15 '26 21:03

Aaron Digulla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!