© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu
Quick Links
Easy Studies

Home Lab Exercise Network Lab Exercise Programs Implementation Of Simple FTP client▼


Implementation Of Simple FTP client:

Algorithm Steps:

    Step 1: start

    Step 2: Create a socket with address family AE_INET type   SOCK_STREAM and default protocol.

    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.

C Program To Implement Simple FTP client

#include #include #include #include #include #include #define PORT_TIME 13 /* "time" (not available on RedHat) */ #define PORT_FTP 21 /* FTP connection port */ #define SERVER_ADDR "127.0.0.1" /* localhost */ #define MAXBUF 1024 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

 
SLogix Student Projects

⇓Student Projects⇓
⇑Student Projects⇑
bottom