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

Local File Transfer Client Code

Program

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)
20 views1 page

Local File Transfer Client Code

Program

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

#include<stdio.

h>
#include<sys/types.h>
#include<sys/stat.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<fcntl.h>
#include<string.h>
#include<netdb.h>
#include<stdlib.h>
#include<unistd.h>

void main()
{
struct sockaddr_in serveraddr;
int clientsock,n,rdret,length;
char filename[20],filedata[300];
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");
clientsock=socket(AF_INET,SOCK_STREAM,0);
if(connect(clientsock,(struct sockaddr*)&serveraddr,sizeof(serveraddr))<0)
{
printf("\nError:Cannot connect...");
exit(0);
}
printf("Enter the name of the file : ");
scanf("%s",filename);
length=strlen(filename);
write(clientsock,filename,length);
rdret=read(clientsock,filedata,300);
printf("\nThe contents of the file: \n\n");
printf("%s",filedata);
close(clientsock);
}
/*
gedit Ftpclient.c
gcc Ftpclient.c
./a.out 127.0.0.1 5678
Enter the name of the file : text.txt

The contents of the file:

Hi!
The file transfer was successful.
*/

You might also like