Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1378987
  • 博文数量: 198
  • 博客积分: 1629
  • 博客等级: 上尉
  • 技术积分: 2743
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-01 15:41
文章分类
文章存档

2023年(6)

2022年(20)

2021年(8)

2020年(3)

2018年(17)

2017年(3)

2016年(3)

2015年(9)

2014年(13)

2013年(17)

2012年(77)

2011年(22)

分类: LINUX

2022-03-25 14:33:56

1、文件下载指令应用

支持断点续传

curl -C - -O "https://curl.haxx.se/download/archeology/curl-7.58.0.tar.gz"
curl -C - -O "https://curl.haxx.se/download/archeology/md5.txt"
直接覆盖
curl "https://curl.haxx.se/download/archeology/curl-7.58.0.tar.gz" -o curl-7.58.0.tar.gz --progress
curl "https://curl.haxx.se/download/archeology/md5.txt" -o md5.txt --progress

系统自带的wget指令下载文件也类似

wget "https://curl.haxx.se/download/archeology/curl-7.58.0.tar.gz"
wget -O curl-7.58.0.tar.gz "https://curl.haxx.se/download/archeology/curl-7.58.0.tar.gz"

 

2、产品固件更新应用demo

upgrade.sh

点击(此处)折叠或打开

  1. #!/bin/sh
  2. url="https://curl.haxx.se/download/archeology/"
  3. while true
  4. do
  5.     #1)download file
  6.     md5_url=${url}"md5.txt"
  7.     #curl md5_url -o md5.txt --progress
  8.     wget -O md5.txt "$md5_url"
  9.     version=$(sed -n 1p md5.txt)
  10.     filename=$(sed -n 2p md5.txt)
  11.     md5=$(sed -n 3p md5.txt)
  12.     version_bak=$(sed -n 1p md5_bak.txt)
  13.     
  14.     echo $version
  15.     echo $filename
  16.     echo $md5
  17.     echo $version_bak
  18.     
  19.     #2)md5sum firmware
  20.     if [[ "$version" != "$version_bak" ]];then
  21.         cp md5.txt md5_bak.txt
  22.         download_url=${url}${filename}
  23.         download_url=${download_url%$'\r'}
  24.         #curl "$download_url" -o $filename --progress
  25.         wget -O $filename "$download_url"
  26.         md5_calc=$(md5sum $filename|cut -d ' ' -f1)

  27.         #3)replace app file---> reboot
  28.         if [ "$md5"=="$md5_calc" ] ; then
  29.             ./kill_app.sh
  30.             #replace upgrade file
  31.             ./run_app.sh
  32.             rm $filename
  33.             time=$(date "+%Y-%m-%d %H:%M:%S")
  34.             echo "${time} upgrade $md5_calc $filename " >> log.txt
  35.         else
  36.             echo "upgrade file md5sum err !"
  37.         fi
  38.     else
  39.         echo "local version is the latest version !"
  40.     fi
  41.     sleep 10
  42. done

3、 md5.txt

 md5.txt文件内置3行关键信息

7.58.0
curl-7.58.0.tar.gz
7e9e9d5405c61148d53035426f162b0a

 

4、curl安装

https://curl.haxx.se/

./configure --prefix=/usr/local/curl
make
sudo make install

export PATH=$PATH:/usr/local/curl/bin
export LD_LIBRARY_PATH=/usr/local/curl/lib:$LD_LIBRARY_PATH

 

5、curl移植

./configure --prefix=/home/dong/curl/curl-7.58.0/_install --host=arm-linux-gnueabihf CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++
make
sudo make install

 

6、 wget编译,安装

# tar zxvf wget-1.9.1.tar.gz 

# cd wget-1.9.1 

# ./configure 

# make 

# make install

 

7、progress

点击(此处)折叠或打开

  1. wget -c https://ftp.gnu.org/gnu/wget/wget-1.19.tar.gz -o load.log
progress.sh

点击(此处)折叠或打开

  1. #wget -c https://ftp.gnu.org/gnu/wget/wget-1.19.tar.gz -o load.log

  2. while true
  3. do

  4. sed -n '/..........\>/p' load.log | sed '$d' | sed -n '$p' | awk '{print $1,$2,$3,$4,$5,$6,$7}'
  5. sed -n '/...\>/p' load.log | sed '$d' | sed -n '$p' | awk '{print $1,$2,$3,$4}'

  6. sleep 1

  7. done

8、progress.c

点击(此处)折叠或打开

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. //类似wget的进度条的实现,实际就是转移符\r的使用,\r的作用是返回至行首而不换行
  5. int main(int argc, char *argv[])
  6. {
  7.     unsigned len = 60;
  8.     char *bar = (char *)malloc(sizeof(char) * (len + 1));
  9.     for (int i = 0; i < len + 1; ++i)
  10.     {
  11.         bar[i] = '#';
  12.     }
  13.     for (int i = 0; i < len; ++i)
  14.     {
  15.         printf("progress:[%s]%d%%\r", bar+len-i, i+1);
  16.         fflush(stdout);//一定要fflush,否则不会会因为缓冲无法定时输出。
  17.         usleep(100000);
  18.         //sleep(1);
  19.     }
  20.     printf("\n");
  21.     return 0;
  22. }

9、checkurl.sh

点击(此处)折叠或打开

  1. #!/bin/bash
  2. usage(){
  3.     echo "Usage:$0 url"
  4.     exit 1
  5. }

  6. checkurl(){

  7.     local num=`curl -I -m 5 -s -w "%{http_code}\n" -o /dev/null $1 |egrep "(200|301|302)"|wc -l`

  8.     if [ $num -eq 1 ]
  9.     then
  10.          echo "ok"
  11.     else
  12.          echo "$1"
  13.     fi
  14. }

  15. main(){

  16.     if [ $# -ne 1 ]
  17.     then
  18.         usage
  19.     fi

  20.     checkurl $1

  21. }

  22. main $*

sh checkurl.sh

10、c语言文件下载,带进度条

https://blog.csdn.net/qq_31629063/article/details/80846673

https://www.cnblogs.com/wainiwann/p/3148884.html


url2file.c

点击(此处)折叠或打开

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <arpa/inet.h>
  5. #include <sys/types.h>
  6. #include <sys/socket.h>
  7. #include <fcntl.h>
  8. #include <unistd.h>
  9. #include <netdb.h>
  10. #include <errno.h>

  11. #define HOST_NAME_LEN 256
  12. #define URI_MAX_LEN 2048
  13. #define RECV_BUF 8192
  14. #define RCV_SND_TIMEOUT (10*1000) //收发数据超时时间(ms)

  15. typedef struct {
  16.     int sock; //与服务器通信的socket
  17.     FILE *in; //sock描述符转为文件指针,方便读写
  18.     char host_name[HOST_NAME_LEN]; //主机名
  19.     int port; //主机端口号
  20.     char uri[URI_MAX_LEN]; //资源路径
  21.     char buffer[RECV_BUF]; //读写缓冲
  22.     int status_code; //http状态码
  23.     int chunked_flag; //chunked传输的标志位
  24.     int len; //Content-length里的长度
  25.     char location[URI_MAX_LEN]; //重定向地址
  26.     char *save_path; //保存内容的路径指针
  27.     FILE *save_file; //保存内容的文件指针
  28.     int recv_data_len; //收到数据的总长度
  29.     time_t start_recv_time; //开始接受数据的时间
  30.     time_t end_recv_time; //结束接受数据的时间
  31. } http_t;

  32. /* 打印宏 */
  33. #define MSG_DEBUG 0x01
  34. #define MSG_INFO 0x02
  35. #define MSG_ERROR 0x04

  36. static int print_level = /*MSG_DEBUG |*/ MSG_INFO | MSG_ERROR;

  37. #define lprintf(level, format, argv...) do{ \
  38.     if(level & print_level) \
  39.         printf("[%s][%s(%d)]:"format, #level, __FUNCTION__, __LINE__, ##argv); \
  40. }while(0)

  41. #define MIN(x, y) ((x) > (y) ? (y) : (x))

  42. #define HTTP_OK 200
  43. #define HTTP_REDIRECT 302
  44. #define HTTP_NOT_FOUND 404

  45. /* 不区分大小写的strstr */
  46. char *strncasestr(char *str, char *sub)
  47. {
  48.     if(!str || !sub)
  49.         return NULL;

  50.     int len = strlen(sub);
  51.     if (len == 0)
  52.     {
  53.         return NULL;
  54.     }

  55.     while (*str)
  56.     {
  57.         if (strncasecmp(str, sub, len) == 0)
  58.         {
  59.             return str;
  60.         }
  61.         ++str;
  62.     }
  63.     return NULL;
  64. }

  65. /* 解析URL, 成功返回0,失败返回-1 */
  66. /* http://127.0.0.1:8080/testfile */
  67. int parser_URL(char *url, http_t *info)
  68. {
  69.     char *tmp = url, *start = NULL, *end = NULL;
  70.     int len = 0;

  71.     /* 跳过http:// */
  72.     if(strncasestr(tmp, "http://"))
  73.     {
  74.         tmp += strlen("http://");
  75.     }
  76.     start = tmp;
  77.     if(!(tmp = strchr(start, '/')))
  78.     {
  79.         lprintf(MSG_ERROR, "url invaild\n");
  80.         return -1;
  81.     }
  82.     end = tmp;

  83.     /*解析端口号和主机*/
  84.     info->port = 80; //先附默认值80

  85.     len = MIN(end - start, HOST_NAME_LEN - 1);
  86.     strncpy(info->host_name, start, len);
  87.     info->host_name[len] = '\0';

  88.     if((tmp = strchr(start, ':')) && tmp < end)
  89.     {
  90.         info->port = atoi(tmp + 1);
  91.         if(info->port <= 0 || info->port >= 65535)
  92.         {
  93.             lprintf(MSG_ERROR, "url port invaild\n");
  94.             return -1;
  95.         }
  96.         /* 覆盖之前的赋值 */
  97.         len = MIN(tmp - start, HOST_NAME_LEN - 1);
  98.         strncpy(info->host_name, start, len);
  99.         info->host_name[len] = '\0';
  100.     }

  101.     /* 复制uri */
  102.     start = end;
  103.     strncpy(info->uri, start, URI_MAX_LEN - 1);

  104.     lprintf(MSG_INFO, "parse url ok\nhost:%s, port:%d, uri:%s\n",
  105.         info->host_name, info->port, info->uri);
  106.     return 0;
  107. }

  108. /* dns解析,返回解析到的第一个地址,失败返回-1,成功则返回相应地址 */
  109. unsigned long dns(char* host_name)
  110. {

  111.     struct hostent* host;
  112.     struct in_addr addr;
  113.     char **pp;

  114.     host = gethostbyname(host_name);
  115.     if (host == NULL)
  116.     {
  117.         lprintf(MSG_ERROR, "gethostbyname %s failed\n", host_name);
  118.         return -1;
  119.     }

  120.     pp = host->h_addr_list;

  121.     if (*pp!=NULL)
  122.     {
  123.         addr.s_addr = *((unsigned int *)*pp);
  124.         lprintf(MSG_INFO, "%s address is %s\n", host_name, inet_ntoa(addr));
  125.         pp++;
  126.         return addr.s_addr;
  127.     }

  128.     return -1;
  129. }

  130. /* 设置发送接收超时 */
  131. int set_socket_option(int sock)
  132. {
  133.     struct timeval timeout;

  134.     timeout.tv_sec = RCV_SND_TIMEOUT/1000;
  135.     timeout.tv_usec = RCV_SND_TIMEOUT%1000*1000;
  136.     lprintf(MSG_DEBUG, "%ds %dus\n", (int)timeout.tv_sec, (int)timeout.tv_usec);
  137.     //设置socket为非阻塞
  138.     // fcntl(sock ,F_SETFL, O_NONBLOCK); //以非阻塞的方式,connect需要重新处理

  139.     // 设置发送超时
  140.     if(-1 == setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout,
  141.             sizeof(struct timeval)))
  142.     {
  143.         lprintf(MSG_ERROR, "setsockopt error: %m\n");
  144.         return -1;
  145.     }

  146.     // 设置接送超时
  147.     if(-1 == setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,
  148.             sizeof(struct timeval)))
  149.     {
  150.         lprintf(MSG_ERROR, "setsockopt error: %m\n");
  151.         return -1;
  152.     }

  153.     return 0;
  154. }

  155. /* 连接到服务器 */
  156. int connect_server(http_t *info)
  157. {
  158.     int sockfd;
  159.     struct sockaddr_in server;
  160.     unsigned long addr = 0;
  161.     unsigned short port = info->port;

  162.     sockfd = socket(AF_INET, SOCK_STREAM, 0);
  163.     if (-1 == sockfd)
  164.     {
  165.         lprintf(MSG_ERROR, "socket create failed\n");
  166.         goto failed;
  167.     }

  168.     if(-1 == set_socket_option(sockfd))
  169.     {
  170.         goto failed;
  171.     }

  172.     if ((addr = dns(info->host_name)) == -1)
  173.     {
  174.         lprintf(MSG_ERROR, "Get Dns Failed\n");
  175.         goto failed;
  176.     }
  177.     memset(&server, 0, sizeof(server));
  178.     server.sin_family = AF_INET;
  179.     server.sin_port = htons(port);
  180.     server.sin_addr.s_addr = addr;

  181.     if (-1 == connect(sockfd, (struct sockaddr *)&server, sizeof(struct sockaddr)))
  182.     {
  183.         lprintf(MSG_ERROR, "connect failed: %m\n");
  184.         goto failed;
  185.     }

  186.     info->sock = sockfd;
  187.     return 0;

  188. failed:
  189.     if(sockfd != -1)
  190.         close(sockfd);
  191.     return -1;
  192. }

  193. /* 发送http请求 */
  194. int send_request(http_t *info)
  195. {
  196.     int len;

  197.     memset(info->buffer, 0x0, RECV_BUF);
  198.     snprintf(info->buffer, RECV_BUF - 1, "GET %s HTTP/1.1\r\n"
  199.         "Accept: */*\r\n"
  200.         "User-Agent: Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)\r\n"
  201.         "Host: %s\r\n"
  202.         "Connection: Close\r\n\r\n", info->uri, info->host_name);

  203.     lprintf(MSG_DEBUG, "request:\n%s\n", info->buffer);
  204.     return send(info->sock, info->buffer, strlen(info->buffer), 0);
  205. }

  206. /* 解析http头 */
  207. int parse_http_header(http_t *info)
  208. {
  209.     char *p = NULL;

  210.     // 解析第一行
  211.     fgets(info->buffer, RECV_BUF, info->in);
  212.     p = strchr(info->buffer, ' ');
  213.     //简单检查http头第一行是否合法
  214.     if(!p || !strcasestr(info->buffer, "HTTP"))
  215.     {
  216.         lprintf(MSG_ERROR, "bad http head\n");
  217.         return -1;
  218.     }
  219.     info->status_code = atoi(p + 1);
  220.     lprintf(MSG_DEBUG, "http status code: %d\n", info->status_code);

  221.     // 循环读取解析http头
  222.     while(fgets(info->buffer, RECV_BUF, info->in))
  223.     {
  224.         // 判断头部是否读完
  225.         if(!strcmp(info->buffer, "\r\n"))
  226.         {
  227.             return 0; /* 头解析正常 */
  228.         }
  229.         lprintf(MSG_DEBUG, "%s", info->buffer);
  230.         // 解析长度 Content-length: 554
  231.         if(p = strncasestr(info->buffer, "Content-length"))
  232.         {
  233.             p = strchr(p, ':');
  234.             p += 2; // 跳过冒号和后面的空格
  235.             info->len = atoi(p);
  236.             lprintf(MSG_INFO, "Content-length: %d\n", info->len);
  237.         }
  238.         else if(p = strncasestr(info->buffer, "Transfer-Encoding"))
  239.         {
  240.             if(strncasestr(info->buffer, "chunked"))
  241.             {
  242.                 info->chunked_flag = 1;
  243.             }
  244.             else
  245.             {
  246.                 /* 不支持其他编码的传送方式 */
  247.                 lprintf(MSG_ERROR, "Not support %s", info->buffer);
  248.                 return -1;
  249.             }
  250.             lprintf(MSG_INFO, "%s", info->buffer);
  251.         }
  252.         else if(p = strncasestr(info->buffer, "Location"))
  253.         {
  254.             p = strchr(p, ':');
  255.             p += 2; // 跳过冒号和后面的空格
  256.             strncpy(info->location, p, URI_MAX_LEN - 1);
  257.             lprintf(MSG_INFO, "Location: %s\n", info->location);
  258.         }
  259.     }
  260.     lprintf(MSG_ERROR, "bad http head\n");
  261.     return -1; /* 头解析出错 */
  262. }

  263. /* 保存服务器响应的内容 */
  264. int save_data(http_t *info, const char *buf, int len)
  265. {
  266.     int total_len = len;
  267.     int write_len = 0;

  268.     // 文件没有打开则先打开
  269.     if(!info->save_file)
  270.     {
  271.         info->save_file = fopen(info->save_path, "w");
  272.         if(!info->save_file)
  273.         {
  274.             lprintf(MSG_ERROR, "fopen %s error: %m\n", info->save_path);
  275.             return -1;
  276.         }
  277.     }

  278.     while(total_len)
  279.     {
  280.         write_len = fwrite(buf, sizeof(char), len, info->save_file);
  281.         if(write_len < len && errno != EINTR)
  282.         {
  283.             lprintf(MSG_ERROR, "fwrite error: %m\n");
  284.             return -1;
  285.         }
  286.         total_len -= write_len;
  287.     }
  288. }

  289. /* 读数据 */
  290. int read_data(http_t *info, int len)
  291. {
  292.     int total_len = len;
  293.     int read_len = 0;
  294.     int rtn_len = 0;

  295.     while(total_len)
  296.     {
  297.         read_len = MIN(total_len, RECV_BUF);
  298.         // lprintf(MSG_DEBUG, "need read len: %d\n", read_len);
  299.         rtn_len = fread(info->buffer, sizeof(char), read_len, info->in);
  300.         if(rtn_len < read_len)
  301.         {
  302.             if(ferror(info->in))
  303.             {
  304.                 if(errno == EINTR) /* 信号中断了读操作 */
  305.                 {
  306.                     ; /* 不做处理继续往下走 */
  307.                 }
  308.                 else if(errno == EAGAIN || errno == EWOULDBLOCK) /* 超时 */
  309.                 {
  310.                     lprintf(MSG_ERROR, "socket recvice timeout: %dms\n", RCV_SND_TIMEOUT);
  311.                     total_len -= rtn_len;
  312.                     lprintf(MSG_DEBUG, "read len: %d\n", rtn_len);
  313.                     break;
  314.                 }
  315.                 else /* 其他错误 */
  316.                 {
  317.                     lprintf(MSG_ERROR, "fread error: %m\n");
  318.                     break;
  319.                 }
  320.             }
  321.             else /* 读到文件尾 */
  322.             {
  323.                 lprintf(MSG_ERROR, "socket closed by peer\n");
  324.                 total_len -= rtn_len;
  325.                 lprintf(MSG_DEBUG, "read len: %d\n", rtn_len);
  326.                 break;
  327.             }
  328.         }

  329.         // lprintf(MSG_DEBUG, " %s\n", info->buffer);
  330.         total_len -= rtn_len;
  331.         lprintf(MSG_DEBUG, "read len: %d\n", rtn_len);
  332.         if(-1 == save_data(info, info->buffer, rtn_len))
  333.         {
  334.             return -1;
  335.         }
  336.         info->recv_data_len += rtn_len;
  337.     }
  338.     if(total_len != 0)
  339.     {
  340.         lprintf(MSG_ERROR, "we need to read %d bytes, but read %d bytes now\n",
  341.             len, len - total_len);
  342.         return -1;
  343.     }
  344. }

  345. /* 接收服务器发回的chunked数据 */
  346. int recv_chunked_response(http_t *info)
  347. {
  348.     long part_len;

  349.     //有chunked,content length就没有了
  350.     do{
  351.         // 获取这一个部分的长度
  352.         fgets(info->buffer, RECV_BUF, info->in);
  353.         part_len = strtol(info->buffer, NULL, 16);
  354.         lprintf(MSG_DEBUG, "part len: %ld\n", part_len);
  355.         if(-1 == read_data(info, part_len))
  356.             return -1;

  357.         //读走后面的\r\n两个字符
  358.         if(2 != fread(info->buffer, sizeof(char), 2, info->in))
  359.         {
  360.             lprintf(MSG_ERROR, "fread \\r\\n error : %m\n");
  361.             return -1;
  362.         }
  363.     }while(part_len);
  364.     return 0;
  365. }

  366. /* 计算平均下载速度,单位byte/s */
  367. float calc_download_speed(http_t *info)
  368. {
  369.     int diff_time = 0;
  370.     float speed = 0.0;

  371.     diff_time = info->end_recv_time - info->start_recv_time;
  372.     /* 最小间隔1s,避免计算浮点数结果为inf */
  373.     if(0 == diff_time)
  374.         diff_time = 1;
  375.     speed = (float)info->recv_data_len / diff_time;

  376.     return speed;
  377. }

  378. /* 接收服务器的响应数据 */
  379. int recv_response(http_t *info)
  380. {
  381.     int len = 0, total_len = info->len;

  382.     if(info->chunked_flag)
  383.         return recv_chunked_response(info);

  384.     if(-1 == read_data(info, total_len))
  385.         return -1;

  386.     return 0;
  387. }

  388. /* 清理操作 */
  389. void clean_up(http_t *info)
  390. {
  391.     if(info->in)
  392.         fclose(info->in);
  393.     if(-1 != info->sock)
  394.         close(info->sock);
  395.     if(info->save_file)
  396.         fclose(info->save_file);
  397.     if(info)
  398.         free(info);
  399. }

  400. /* 下载主函数 */
  401. int http_download(char *url, char *save_path)
  402. {
  403.     http_t *info = NULL;
  404.     char tmp[URI_MAX_LEN] = {0};

  405.     if(!url || !save_path)
  406.         return -1;

  407.     //初始化结构体
  408.     info = malloc(sizeof(http_t));
  409.     if(!info)
  410.     {
  411.         lprintf(MSG_ERROR, "malloc failed\n");
  412.         return -1;
  413.     }
  414.     memset(info, 0x0, sizeof(http_t));
  415.     info->sock = -1;
  416.     info->save_path = save_path;

  417.     // 解析url
  418.     if(-1 == parser_URL(url, info))
  419.         goto failed;

  420.     // 连接到server
  421.     if(-1 == connect_server(info))
  422.         goto failed;

  423.     // 发送http请求报文
  424.     if(-1 == send_request(info))
  425.         goto failed;

  426.     // 接收响应的头信息
  427.     info->in = fdopen(info->sock, "r");
  428.     if(!info->in)
  429.     {
  430.         lprintf(MSG_ERROR, "fdopen error\n");
  431.         goto failed;
  432.     }

  433.     // 解析头部
  434.     if(-1 == parse_http_header(info))
  435.         goto failed;

  436.     switch(info->status_code)
  437.     {
  438.         case HTTP_OK:
  439.             // 接收数据
  440.             lprintf(MSG_DEBUG, "recv data now\n");
  441.             info->start_recv_time = time(0);
  442.             if(-1 == recv_response(info))
  443.                 goto failed;

  444.             info->end_recv_time = time(0);
  445.             lprintf(MSG_INFO, "recv %d bytes\n", info->recv_data_len);
  446.             lprintf(MSG_INFO, "Average download speed: %.2fKB/s\n",
  447.                     calc_download_speed(info)/1000);
  448.             break;
  449.         case HTTP_REDIRECT:
  450.             // 重启本函数
  451.             lprintf(MSG_INFO, "redirect: %s\n", info->location);
  452.             strncpy(tmp, info->location, URI_MAX_LEN - 1);
  453.             clean_up(info);
  454.             return http_download(tmp, save_path);

  455.         case HTTP_NOT_FOUND:
  456.             // 退出
  457.             lprintf(MSG_ERROR, "Page not found\n");
  458.             goto failed;
  459.             break;

  460.         default:
  461.             lprintf(MSG_INFO, "Not supported http code %d\n", info->status_code);
  462.             goto failed;
  463.     }

  464.     clean_up(info);
  465.     return 0;
  466. failed:
  467.     clean_up(info);
  468.     return -1;
  469. }

  470. /****************************************************************************
  471. 测试用例:
  472. (1)chunked接收测试
  473. ./a.out "http://www.httpwatch.com/httpgallery/chunked/chunkedimage.aspx" test.aspx
  474. (2)重定向测试
  475. ./a.out "192.168.10.1/main.html" test.txt
  476. (3)错误输入测试
  477. ./a.out "32131233" test.txt
  478. (4)根目录输入测试
  479. ./a.out "" test.txt
  480. (5)端口号访问测试
  481. ./a.out "192.168.0.200:8000/FS_AC6V1.0BR_V15.03.4.12_multi_TD01.bin" test.txt
  482. ****************************************************************************/

  483. int main(int argc, char *argv[])
  484. {
  485.     if(argc < 3)
  486.         return -1;

  487.     http_download(argv[1], argv[2]);
  488.     return 0;
  489. }

原文路径:https://www.cnblogs.com/dong1/p/9510350.html

阅读(582) | 评论(0) | 转发(0) |
0

上一篇:驱动加载脚本

下一篇:获取Wi-Fi链接信号

给主人留下些什么吧!~~