File Transfer Protocol Client in TCP CS1305- NETWORK C Language Programing Linux OS

Step by step procedure: Create a socket and mention the port address, address family and the IP address.
Create a connection with the source using connect ().
Get the source file name which has to be transferred.
Get the destination file name or which the contents of file have to the stored and sent the filename to the server
Receive the contents of the file and close the connections.
See ->The Basic FTP SYNTAX command C Language Programing

Source code of the programming FTP CLIENT:
#include<sys/socket.h>
#include<sys/types.h>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<unistd.h>
#define SER_PORT 5500
int main(int count,char *arg[])
{ int a,n;
FILE *f1,*f2;
int clisock;
char str[25],str1[25];
struct sockaddr_in cliaddr;
cliaddr.sin_port=htons(SER_PORT);
cliaddr.sin_family=PF_INET;
cliaddr.sin_addr.s_addr=inet_addr(arg[1]);
clisock=socket(PF_INET,SOCK_STREAM,0);
if(clisock<0)
{
perror("\n socket");
exit(0);
}
if(connect(clisock,(struct sockaddr*)&cliaddr,sizeof(cliaddr))<=0)
{
perror("\n connect");
exit(0);
}
printf("\n client connected to %s",arg[1]);
printf("\n enter the source file:");
scanf("%s",str);
if(send(clisock,str,sizeof(str),0)<0)
{
printf("\n data could not be send");
exit(0);
}
printf("\n enter the destination flie:");
scanf("%s",str1);
if(send(clisock,str1,sizeof(str1),0)<0)
{
printf("send error");
close(clisock);
exit(0);
}
close(clisock);
return 0;
}
OUTPUT FTP CLIENT

[Linux28@localhost network]$ Cat>input.dat
Welcome To Linux Network
[Linux28@localhost network]$cc ftpclient.c

[Linux28@localhost network]$./a.out 192.168.1.111
Client connected to 192.168.1.111

Client-enter the source file:input.dat
Enter destination file:output.dat

Post a Comment

0 Comments