#include <stdio.h>
#include <string.h>
void parse_ftpurl(char * url,
char *user,char *passwd,
char *ipaddr, uint *port)
{
char * p, *host;
char *newURL;
if(!url) return;
if(strncmp(newURL, "ftp://", 6) != 0) {
printf("error ftp URL\n");
} else {
newURL = (char *) malloc(strlen(url)+1);
strcpy(newURL, url + 6);
}
/* username / password */
p = strchr(newURL, '@');
if(p)
*p++ = 0, host = p;
else
host = newURL;
if(p) {
p = strchr(newURL, ':');
if(p) {
*p++ = 0;
strcpy(passwd, p);
}
strcpy(user, newURL);
}
/* host / port */
p = strchr(host, ':');
if(!p) {
*port = 21;
} else {
*port = atoi(p + 1);
*p = 0;
}
strcpy(ipaddr, host);
free(newURL);
}
/*ftp://user:passwd@192.168.1.1:21*/
int main(int argc,char
解析包含用户名密码的FTPURL
最新推荐文章于 2023-08-18 15:49:15 发布
本文详细介绍了如何在C语言环境下,针对包含用户名和密码的FTPURL进行解析,主要涉及Linux系统的字符串处理技巧和FTP协议的理解。通过实例代码,阐述了如何提取URL中的关键信息,实现安全有效地连接FTP服务器。
订阅专栏 解锁全文

6759

被折叠的 条评论
为什么被折叠?



