从 C 调用期望文件

标签 c linux ubuntu expect ubuntu-12.04

我编写了一个 ftp.exp 文件,该文件将 C 应用程序的日志文件发送到服务器。

#!/usr/bin/expect
set timeout -1
spawn ftp xxx.xxx.xxx 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

脚本运行良好,但如何从 C 应用程序 执行文件。

最佳答案

您需要使用 libexpect并从其 api 调用您的脚本。

我只找到了它的 php 绑定(bind),但我这里没有 Debian 可以告诉你哪个包提供了基础包。

关于从 C 调用期望文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12331259/

相关文章:

c - mac osx 上的 select() 套接字系统调用需要很长时间才能读取

c - vector : Static versus Dynamic 的赋值

对如何添加到另一个结构中的链表结构感到困惑

c++ - 无符号字符串

linux - 如何从终端获取 CSV 尺寸

Linux 64 位 NASM 程序问题

ubuntu - apache Storm yaml blockmappingstart 消息

c - C 中的段错误(核心已转储)- 使用 PTHREADS 时

c++ - Tesseract + OpenCV + Linux

c++ - 在 C++ 中使用 dlopen() 和 dlsym() 从 .so 库中获取对象