update
This commit is contained in:
parent
5f76f74c16
commit
af4a9f8d59
@ -12,7 +12,7 @@
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const int port = 7332;
|
||||
const char ip[512] = "192.168.0.102";
|
||||
const char ip[512] = "127.0.0.1";
|
||||
struct sockaddr_in endpoint;
|
||||
struct dirent **namelist;
|
||||
char buff[512];
|
||||
@ -25,6 +25,19 @@ int main(int argc, char **argv)
|
||||
addrlen = sizeof(struct sockaddr_in);
|
||||
ssize_t count = 0;
|
||||
|
||||
if ((sdsocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||
{
|
||||
printf("socket() failed\n");
|
||||
return 1;
|
||||
}
|
||||
if (connect(sdsocket, (struct sockaddr *)&endpoint, addrlen) < 0)
|
||||
{
|
||||
printf("connect() failed\n");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
printf("CONNECTED\n");
|
||||
|
||||
while (1)
|
||||
{
|
||||
start:
|
||||
@ -43,23 +56,12 @@ int main(int argc, char **argv)
|
||||
goto start;
|
||||
}
|
||||
|
||||
if ((sdsocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||
{
|
||||
printf("socket() failed\n");
|
||||
return 1;
|
||||
}
|
||||
if (connect(sdsocket, (struct sockaddr *)&endpoint, addrlen) < 0)
|
||||
{
|
||||
printf("connect() failed\n");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
printf("CONNECTED\n");
|
||||
|
||||
send(sdsocket, buff, 512, 0);
|
||||
|
||||
if (strncmp("FTP", buff, 3) == 0)
|
||||
{
|
||||
bzero(name_file, 512);
|
||||
|
||||
ssize_t total = 0;
|
||||
strncpy(name_file, buff + 4, 509);
|
||||
printf("Name of file :%s\n", name_file);
|
||||
|
@ -41,13 +41,13 @@ int main(int argc, char **argv)
|
||||
|
||||
while (1)
|
||||
{
|
||||
start:
|
||||
|
||||
while ((sdconnection =
|
||||
accept(sdsocket,
|
||||
(struct sockaddr *)&endpoint,
|
||||
&addrlen)) >= 0)
|
||||
{
|
||||
|
||||
start:
|
||||
printf("CONNECT FROM : %s\n ", inet_ntoa(endpoint.sin_addr));
|
||||
|
||||
bzero(buff, 512);
|
||||
@ -76,8 +76,9 @@ int main(int argc, char **argv)
|
||||
}
|
||||
free(namelist);
|
||||
|
||||
if(s = send(sdconnection, names_files, 512, 0) == 512){
|
||||
printf("Done Sending\n");
|
||||
if (s = send(sdconnection, names_files, 512, 0) == 512)
|
||||
{
|
||||
printf("SEND SUCCESS");
|
||||
goto start;
|
||||
}
|
||||
}
|
||||
@ -126,6 +127,7 @@ int main(int argc, char **argv)
|
||||
printf("Downloading succes, numer of bytes = %ld\n", total);
|
||||
|
||||
fclose(file);
|
||||
goto start;
|
||||
}
|
||||
else if (strncmp("EXIT", buff, 4) == 0)
|
||||
{
|
||||
@ -171,6 +173,7 @@ int main(int argc, char **argv)
|
||||
printf("Send success, number of bytes: %ld\n", count);
|
||||
|
||||
fclose(file);
|
||||
goto start;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user