📄 ftpdown.c
字号:
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "ConfigInfo.h"
#include "ftpdown.h"
#define MAXPlNum 1024
#define MAXLINE 1024
char DownLoadingName[MAXPlNum];
int flag;
int cn;
char pname1[MAXLINE][MAXLINE]; //downloading program list
struct stat statbuf;
struct VedioPLNumber Vplnumber;
extern struct IniConfig Conf;
extern pthread_mutex_t mut;
off_t filesize;
char downfilepath[MAXPlNum]="media";
void *Commthread2_Loop()
{
int i=0,ret,j;
pthread_mutex_lock(&mut);
while(1)
{
#if 1
char *fname1="PL.txt";
memset(Vplnumber.DnLoadingName,0,sizeof(Vplnumber.DnLoadingName));
/*get download file num*/
cn=GetDn_File(TempDownLoading_FileList );
for(i=0;i<cn;i++)
printf("%s\n",pname1+i);
printf("cn=%d\n",cn);
for(i=0;i<cn-2;i++){
pthread_mutex_lock(&mut);
/*construct full downfilepath*/
strcat(downfilepath,strrchr((pname1+i),'/'));
printf("%s\n",downfilepath);
/*check needing to download file wether exsit or not*/
if(stat(downfilepath,&statbuf)<0){
perror("file open");
}
/*get local download file size*/
filesize=statbuf.st_size;
if(filesize<=0)
flag=0;
else{
flag=1;
filesize=0;
statbuf.st_size=0;
}
memset(downfilepath,0,sizeof(downfilepath));
strcpy(downfilepath,"media");
/*if download file is not exsit,so that download a new file*/
if(flag==0){
memset(Vplnumber.DnLoadingName,0,sizeof(Vplnumber.DnLoadingName));
strcpy(Vplnumber.DnLoadingName,strrchr((pname1+i),'/')+1);
ftpcmd(Conf.FtpHost, "-g",Conf.FtpUser,Conf.FtpPass, (pname1+i), "media");
Vplnumber.DnCompleteFlag=1;
}/*if download file is exsit and size is larger than zero,so that download file at restart point */
else{
ftpcmd(Conf.FtpHost,"-rg",Conf.FtpUser,Conf.FtpPass,(pname1+i),"media");
}
}
#endif
pthread_mutex_unlock(&mut);
sleep(10);
}
return ;
}
int GetDn_File( char *filename)
{
int i=0,k=0;
int retv=0;
int rt;
FILE *fp=NULL;
char *line[MAXLINE];
char *SaveBuf[MAXLINE];
char *path[MAXLINE];
if((fp=fopen(filename,"r"))==NULL)
return (-3);
while(retv>=0)
{
retv=FileGetLine(fp,(line+i),MAXLINE);
//printf("ret=%d\n",retv);
if(retv>0){
// printf("%s\n",(line+i));
rt=SubStringV3((line+i), "<", ">", MAXLINE,(SaveBuf+i));
//printf("rt=%d\n",rt);
if(rt==1)
{
memset(Vplnumber.DnPlNo,0,sizeof(Vplnumber.DnPlNo));
strTrimlf(line+i);
strcpy(Vplnumber.DnPlNo,(line+i));
// printf("%s\n",Vplnumber.DnPlNo);
}
if(rt>0) continue;
getpath((SaveBuf+i),MAXLINE,(path+i));
strcpy((pname1[k]),(path+i));
k++;
}
// printf("retv=%d\n",retv);
i++;
}
fclose(fp);
return k;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -