0% found this document useful (0 votes)
7 views1 page

FTP Server

Uploaded by

sital27569
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

FTP Server

Uploaded by

sital27569
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

#include<stdio.

h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<fcntl.h>
#include<string.h>
#include <unistd.h>
void main()
{
struct sockaddr_in clientaddr,serveraddr;
int serversock,newserversock,clientsize,n,f,rc;
char filename[100],filedata[300];
fflush(stdin);
serversock=socket(AF_INET,SOCK_STREAM,0);
bzero((char*)&serveraddr,sizeof(serveraddr));
serveraddr.sin_family=AF_INET;
serveraddr.sin_port=2000;
serveraddr.sin_addr.s_addr=inet_addr("127.0.0.1");
bind(serversock,(struct sockaddr*)&serveraddr,sizeof(serveraddr));
sizeof(serveraddr);
listen(serversock,5);
while(1)
{
clientsize=sizeof(clientaddr);
newserversock=accept(serversock,(struct sockaddr*)&clientaddr,&clientsize);
n=read(newserversock,filename,100);
filename[n]=0;
printf("\nThe requested file from the client is %s.\n",filename);
//write(1,filename,n);
f=open(filename,O_RDWR);
n=read(f,filedata,300);
printf("\nThe contents of the file: \n\n");
printf("%s",filedata);
write(newserversock,filedata,n);
}
close(serversock);
close(newserversock);
}
/*
gedit Ftpserver.c
gcc Ftpserver.c
./a.out 5678

The requested file from the client is text.txt.

The contents of the file:

Hi!
The file transfer was successful.
*/

You might also like