FTP clients cannot talk to TCP server I have implemented - c

I'm implementing my own TCP server. So far I can make a connection, that works fine, I can connect to any client. However when I want to send or receive messages from the client it goes wrong. The following is a snippet of the last part of my server, where I want to send the message WeLcOmE to my client (I'm using C programming language & Linux as the OS):
// Accept a connection request
int clientAddress = sizeof(client_address);
int new_socket = accept(door_socket, (struct sockaddr *) &client_address,
&clientAddress);
if (new_socket < 0)
perror("ERROR on accept");
// Receive data from socket, send data to socket
char buff[8] = "WeLcOmE";
send(new_socket, buff, sizeof(buff), 0);
// Close socket
close(new_socket);
close(door_socket);
return 0;
Running my server with a Filezilla Client this is what I get:
Status: Resolving address of ubuntu
Status: Connecting to 127.0.1.1:3471...
Status: Connection established, waiting for welcome message...
Response: WeLcOmE
Error: Could not connect to server
Status: Waiting to retry...
Status: Resolving address of ubuntu
Status: Connecting to 127.0.1.1:3471...
Status: Connection attempt failed with "ECONNREFUSED - Connection
refused by server".
Error: Could not connect to server
Running my server with the ftp Linux built-in client I get:
ftp> WeLcOmE421 service not available remote server has closed connection
I don't understand why is this happening. Any help is appreciated.

As you have yourself stated, you have implemented a "TCP" server. All the server does is that it sends the "WeLcOmE" string to any TCP client that connects to the server.
If you connect with an FTP client to the server, the client gets the "WeLcOmE" string, and as that does not conform to the FTP protocol specification, the client errors.
The same would happen, if you connect with any other client that uses a specific protocol, e.g. a web browser [HTTP], a terminal client [SSH or Telnet], etc.
Now the question is, what you are trying to achieve:
Either you want to implement an FTP server. For that you need to read the FTP specification and implement your server according to it. That's an immense task and in general you do not want to do that. You better take an existing implementation. Either an FTP server library and build your custom FTP server on it. Or take a complete open source FTP server and customize it to your needs.
Or you just play with your toy TCP server and you want to test it. For that use any TCP client that can work in "raw" mode by reading from the socket and just displaying what it gets, without trying to interpret the data in any way. You can use PuTTY in a "raw" connection mode. See section Making raw TCP connections in PuTTY documentation.

Related

Camel Netty client: connect and then wait/listen for server tcp

I'm trying to create a Camel/Netty TCP client that works as follows:
connect to remoteserver:1234
send a handshake message (pretend it's the string "handshake")
leave this connection open
wait/listen for TCP messages from the server and reply to them
Here's a simple hello-world server.
from("netty:tcp://localhost:8001?textline=true&sync=true") //
.process((exchange) -> {
String msgReceived = exchange.getIn().getBody(String.class);
exchange.getOut().setBody("hello " + msgReceived);
});
I can open a command line TCP connection to this, type in text, and receive my hello-world reply.
Now how do I structure an analogous client that likewise just waits for messages and replies?
When you say "wait/listen for TCP messages from the server and reply to them" you are reversing the roles, now the client acts like a server and the server like a client.
What you could do is set up an incoming route in the client listening on a given port and use the initial handshake message to the server to communicate the client's IP and port.

Enabling Keepalive on ODBC client for MSSQL Server

I have got step by step information on how to enable/set/modify the keep alive option on MSSQL Server side. But, how to do the same while using ODBC client to connect with MSSQL Server? This is mainly used to close the socket on client side and start reconnecting.
I came across an option called "Connect Timeout
-or-
Connection Timeout", in connection string, which disconnects if there is no connection after that timeout. But i hope TCP keep alive does more than this.
Couple of options would do for me,
1) Is there a keepalive option that could be added in connection string (similar to postgres)?
2) How to get the client socket fd, which connects with the MSSQL Server, (without using OS commands) so that, i could use setsockopt API and enable keep alive

running server socket infinitely

I am new to socket programming.Please provide me some techniques to run the server socket infinitely even if I close the client socket using close(clientfd) in C programming (the server has to wait in accept()for the next client connection even if the current connection is closed ). Also kindly help me how the close() in client side affects the socket in server side.

Ftp passive mode: connect to server

I need to help with my ftp client application. I successfuly connect to server with usename and password and send PASV message. I recived IP and port, but i do not know what to do next. I know that I must connect to IP and port, but I do not know how.
Can somebody give me example of code how to connect and recive message from server?
You already have the code which successfully connected to port 21 on the server, the same code will also work to connect to the IP address and port number that was returned in the PASV response.
BUT
You do not want to make this second connection until it is time to transfer some data. The first connection you established is for commands and responses to commands. The connection you make to the port returned by PASV is for the transfer of data following a command that actually transfers a file, for example RETR or LIST.

sent data to paticular socket from server when have multiple client

I have 4 different application running.so every application can send data to server. now i want to send data to paticular socket (server and client are done through socket programming)
from server side.
When you create a socket, first you establish a connection between a server and a client (using connect system call on the client side, and bind, listen, and accept system calls on the server side). You can have many such connections, from a server to different clients. The server can send data on any of these established connections.
The Sockets Tutorial can assist you in this case.
If you want multiple reads/writes by the server to happen at the same time, you have to use non-blocking sockets or multiple threads.
(Assuming you're using TCP/IP, or UDP).
A socket endpoint is the IP address and port number combined. So, on your host you would have your various servers listen on different port numbers. For example a web server may listen on port 80, ssh on a different port etc.

Resources