
two way to do it :
1>File Alteration Monitor(known as FAM and sgi_fam, provides a subsystem developed by Silicon Graphics for Unix-likeoperating systems.)
server runs at nfs server ,while client runs at client pc
2>server runs a program using inotif monitor file changs ,then send changs to remote client by socket. it is a question of adding some socket ipc to your client progarm.
/*头文件
*/
#define SRCPATH "srcpath/"
#define DSTPATH "dstpath/"
int movefile()
{
DIR *dir
struct dirent *dt
FILE *fp1,*fp2
char filename1[256],filename2[256]
char buf[1024]
int readsize,writesize
if((dir = opendir(SRCPATH)) == NULL)
{
printf("opendir %s error\n",SRCPATH)
return -1
}
memset(filename1,0,sizeof(filename1))
strcpy(filename1,SRCPATH)
memset(filename2,0,sizeof(filename2))
strcpy(filename2,DSTPATH)
while(1)
{
while((dt = readdir(dir)) != NULL)
{
if(strcmp(dt->d_name,".")==0||strcmp(dt->d_name,"..")==0)
{
continue
}
//如果这个目录里 还有目录,可以在这加判断
//这里假设初始为空目录
strcat(filename1,dt->d_name)
strcat(filename2,dt->d_name)
//如果进程资源较少可以直接用linux系统命令
fp1 = fopen(filename1,"rb")
if(fp1==NULL)
{
printf("open %s failed /n",filename1)
return -1
}
fp2 = fopen(filename2,"wb")
if(fp2==NULL)
{
printf("open %s failed /n",filename2)
fclose(fp1)
return -1
}
while((readsize = fread(buf,sizeof(buf),1,fp1))>0)
{
//total += readsize
memset(buf,0,sizeof(buf))
writesize = fwrite(buf,sizeof(buf),1,fp2)
if(writesize!==readsize)
{
printf("write error")
return -2
fclose(fp1)
fclose(fp2)
}
}
fclose(fp1)
fclose(fp2)
rmdir(filename2)
}
}
}
int main(int argc,char **argv)
{
pthread_t id1
int ret
ret = pthread_create(&id1, NULL, (void*)movefile, NULL)
return ret
}
自己调试下
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)