Call expect file from C

I coded a ftp.exp file which sends a log file of a C application to a server.

set timeout -1
spawn ftp 21
match_max 100000
expect -re {[2]{2,}[0]{1,}}
send -- "usrxxxx"
expect -exact "usrxxxxx"
send -- "\r"
expect -re {[3]{2,}[1]{1,}}
send -- "xxxx\r"
expect -exact "\r
230 Access granted for xxxxxxxxxx !\r
Remote system type is UNIX.\r
Using binary mode to transfer files.\r
ftp> "
send -- "put /home/User/test.txt test2.txt\r"
expect -exact "put /home/User/test.txt test2.txt\r"
send -- "\r"
expect -re {[2]{2,}[6]{1,}}
send -- "quit\r"
expect eof

The script works fine but how can I execute the file from a C Application.


You can use system(3) or popen(3) library functions to run your expect script from your C code. These functions are using syscalls like fork(2), execve(2), pipe(2), dup(2), waitpid(2) which you could also use by yourself.

I strongly suggest learning more about advanced unix programming and advanced linux programming; there are some concepts and tricks to learn.

I believe you'll better use ssh (with scp) than an expect script sending plain passwords on the wire to a distant remote FTP server (there are some security issues with your approach).

You need to use the libexpect and call your script from its api.

I found only the php bindings for it, but I have no Debian here to tell you what package provides the base package.

Need Your Help

Problem with ObservableCollection and INotifyPropertyChanged in MVVM

c# mvvm

I have a chart control in XAML, and datapoints that are bind to the control.