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