Repository navigation
Expand file tree
/
Copy pathfserver.cpp
More file actions
73 lines (46 loc) · 1.54 KB
/
Copy pathfserver.cpp
File metadata and controls
73 lines (46 loc) · 1.54 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
#include "fserver.h"
void transact_with_client(char * backup_dir, int sock)
{
char ch[100], direc[100];
int fd;
int n =read(sock,ch,sizeof(ch)); // Recieving "filename"
while(n!=0)
{
send(sock,"Handshaking Completed",21,0); //Send Confirmation
//**************************************************************
bzero(direc,sizeof(direc));
read(sock,direc,sizeof(direc)); //Reading folder name
send(sock,"Folder Recieved",15,0); //Send Confirmation
if (strcmp(ch,"filename")==0)
{
char fn[30];
bzero(fn,sizeof(fn));
n=read(sock,fn,sizeof(fn)); //fn = file name
cout << "File Name : " << fn << endl;
send(sock,"Received",8,0);
cout<<"-----------------------------------"<<endl;
string st = (char*)fn; // st contains file name
string ch = (char*)direc; // ch contains Folder name
string path = (char*)backup_dir;
string makedir=path+ch;
mkdir(makedir.c_str(),0777);
st=path+ch+"/"+st;
cout<<"full path of file to be backedup is : "<<st<<endl;
bzero(direc,sizeof(direc));
cout<<"-----------------------------------"<<endl;
strcpy(fn,st.c_str());
fd = open(fn,O_CREAT|O_WRONLY,0777);
bzero(fn,sizeof(fn));
}
else if (strcmp(ch,"end")==0)
{
close(fd);
}
else
{
write(fd,ch,n);
bzero(ch,sizeof(ch));
}
n =read(sock,ch,sizeof(ch));
}
}