You are on page 1of 2

Algorithm Steps:

Step 1: start
Step 2: Create a socket with address family AE_INET type
efault protocol.

SOCK_STREAM and d

Step 3: Initialize the socket and set its attribute set required port no.
Step 4: Connect to server using connect () function to initiate the request.
Step 5: Receive the string from the server and print it at the console.
Step 6: stop.
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/socket.h>
#include<netinet/in.h>
#include<time.h>
#define PORT_TIME
#define PORT_FTP
#define SERVER_ADDR
#define MAXBUF

13
21
"127.0.0.1"
1024

/* "time" (not available on RedHat) */


/* FTP connection port */
/* localhost */

int main()
{ int sockfd;
struct sockaddr_in dest;
char buffer[MAXBUF];
/*---Open socket for streaming---*/
if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
{
perror("Socket");
exit(errno);
}
/*---Initialize server address/port struct---*/
bzero(&dest, sizeof(dest));
dest.sin_family = AF_INET;
dest.sin_port = htons(PORT_FTP);
if ( inet_aton(SERVER_ADDR, &dest.sin_addr.s_addr) == 0 )
{
perror(SERVER_ADDR);
exit(errno);
}
/*---Connect to server---*/
if ( connect(sockfd, (struct sockaddr*)&dest, sizeof(dest)) != 0 )
{
perror("Connect ");
exit(errno);
}
/*---Get "Hello?"---*/
bzero(buffer, MAXBUF);
recv(sockfd, buffer, sizeof(buffer), 0);
printf("%s", buffer);

/*---Clean up---*/
close(sockfd);
return 0;
}

SAMPLE INPUT OUTPUT:


$ gcc Ftpclient.c -o Ftpclient.exe
$ Ftpclient.exe
220 Microsoft FTP Service

You might also like