免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1789 | 回复: 0
打印 上一主题 下一主题

[C] [求助]利用C语言实现下载URL,并保存到指定目录,如果目录不存在,递归创建 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-09-06 23:54 |只看该作者 |倒序浏览
8可用积分
本帖最后由 oopul 于 2012-09-06 23:55 编辑

要求跨平台(Windows/Linux) (如能同时支持Mac OSX / BSD最好)
如页面需要跳转,并跳转下载,其他情况返回错误信息HTTP代码(403/304/302/301/500/503/504/501)之类

程序样例
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#ifdef WIN32
#include <winsock2.h>
#pragma comment( lib , "ws2_32.lib")
#else
#include <unistd.h>
#include <fcntl.h>
#include <netdb.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
int create_dir(char *url)
{
        //需要您补充
}
int download(char *url,char *dir)
{
        //需要您补充
}
int main(int argc,char** argv)
{
        if(argc!=3)
        {
                 printf("usage: %s http://www.baidu.com/index.php C:/test/test1/test2/index.php",argv[0]);
                return 0;     
        }
        return download(argv[1],argv[2]);
}

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP