Repository navigation
Expand file tree
/
Copy pathfclient.cpp
More file actions
91 lines (71 loc) · 2.16 KB
/
Copy pathfclient.cpp
File metadata and controls
91 lines (71 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "fclient.h"
void sendfromdirectory(char *directory,int sd)
{
char buf[100];
struct dirent *dir;
char path[50]="";
strcat(path,"/home/sagar/new/");
char tempdir[30],targetdir[30];
strcpy(tempdir,directory); //directory -> /home/sagar/new/
char *str=strtok(tempdir,"/");
char *tok=str;
while(str!=NULL) //home/sagar/new/
{
tok=str;
str=strtok(NULL,"/"); // new
}
strcat(path,tok); // /home/sagar/etc/new
strcat(path,"/"); // /home/sagar/etc/new/
DIR *d=opendir(directory); // /home/sagar/new/
if (d)
{
char msg[25];
while((dir=readdir(d))!=NULL)
{
if ( (strcmp(dir->d_name,".")==0) || (strcmp(dir->d_name,"..")==0))
{
continue;
}
else if(dir->d_type==DT_DIR) //Checking for directory
{
cout<<"Sub Directory :"<<dir->d_name<<endl;
}
else
{
char fpath[50]="";
strcat(fpath,directory); // /home/sagar/new/
strcat(fpath,dir->d_name); // /home/sagar/new/file1.txt
cout <<"Files to be backedup : "<<fpath << endl;
int fd = open(fpath,O_RDONLY);
send(sd,"filename",9,0); //handshaking
recv(sd,msg,sizeof(msg),0); //Recieving confirmation
bzero(msg,sizeof(msg));
send(sd,tok,sizeof(tok),0); //Sending folder name
recv(sd,msg,sizeof(msg),0); //recieving msg
send(sd,dir->d_name,strlen(dir->d_name),0); //Send filename
recv(sd,msg,sizeof(msg),0);
if(fd)
{
int n = read(fd,buf,sizeof(buf));
while(n!=0)
{
send(sd,buf,n,0);
recv(sd,msg,sizeof(msg),0);
bzero(buf,sizeof(buf));
n = read(fd,buf,sizeof(buf));
buf[n]='\0';
}
}
else
{
cout<<"Error in opening files : " <<endl;
}
send(sd,"end",3,0);
recv(sd,msg,sizeof(msg),0);
close(fd);
}
}
}
else
cout<<"Error in opening source directory " <<endl;
}