ftp server in C - c

I have to develop 1 FTP (simple) server in C.
What do i mean with simple??
I mean that FTP server has to support:
authentication (USER, PASS, PORT)
change directory (CD)
file listing (LIST)
file retrive (RETR)
I have just developed as "split part" the numbers 1-2-3-4 and i have to merge them into main.c. So no problem with them.
What i don't understand is how to "receive" communications from the client.I mean how can implement what the client wants (USER, PASS, CD, LIST, RETR)?
I've read the rfc959 but i have not totally understood the communication between client and sever.
Summary:
client connect to server (so into the server this part is the socket "accept(..)"), rigth?
1a server send to client "you are connected" right?
client send to server user,password (file 1, auth.c but i don't know how to read when client send to the server the user and password request)
after successful login the server send file list (part 3, list.c, no problem)
the client send to the server the file it wants to download or the changedir command (again, how to read this info from client's request?)
i hope you have understand :)
EDIT: i'm on GNU/Linux

Although your question is little confusing, I am trying to answer it. Take command line parameters like "Username Password" and pass these argv[] through send to Server and receive using recv at Server end. For better understanding, refer the link Client.cpp
Hope this solves your confusion.

If you're using the Berkeley sockets API (your mentioning accept() implies that you are), you typically use recv() to read data from a socket. You need to read from the socket the client is connecting to, then inspect what you got to determine if it's a valid command that you can handle.

I was looking for a code to learn the workings of ftp with sockets and found filework on google code and the code clear and simple.
URL: http://code.google.com/p/ifilework

Related

Sending requests using Sockets through a SOCKS5 Proxy Server in C

I have a simple networking program for sending and responding to HTTP requests/responses. However, if I wanted to send a HTTP or another request via a SOCKS5 proxy, how would I go about this? I'm using C Unix sockets.
I could solve this by creating a proxy server in Linux. However, my intention is so that I can send this to a proxy server I do not own so that it can be forwarded to the destination server. I couldn't seem to find a library. I found an RFC for it which I've read https://www.rfc-editor.org/rfc/rfc1928.txt , but i'm still not 100% unsure how to format my request.
Am I supposed to send the segments for the handshakes as hex? If so, would I send a string of hex 0F3504 or \x0F \x35 \x04 or 0x0F3504? Another question is do i need to denote that header = value in the message, or does the SOCKS5 server know what header i am referring to by the position of the byte it is looking at from the message I've sent?
Any clear up would be very much appreciated
Some time ago I wrote an open source C library that may help you: https://github.com/brechtsanders/proxysocket
Maybe you can use the library. Its quite easy, just replace the connect() with stuff from the library and for the rest you can keep the rest of your code that uses the socket that is returned.
Or you can take a peek in the code to see how it's done there.

Send memory variables from Server to Client in open62541

I'm trying to create a bridge in C Language that uses two protocols : OPC-UA and MODBUS.
Between the client and the bridge I used the protocol open62541 to ask for some data of any type. When the bridge receive the request, the memory requests start, from the brigde with the protocol MODBUS, to the MODBUS server, that should send back those memory variable asked.
My problem is that I cannot find any way to see the point in the code, where the Server recieve the Client request.
I need to find how to send those memory variables back from the server to the Client.
I would be glad if someone has the solution.
By guessing I assume you mean a ReadRequest and you want to find out where this read request is handled in the server?
It could be this one: Service_Read
https://github.com/open62541/open62541/blob/71e9a44d1aec5bc0cce465c8daefe47883b25f6c/src/server/ua_services_attribute.c#L394
Or also the Operation_Read:
https://github.com/open62541/open62541/blob/71e9a44d1aec5bc0cce465c8daefe47883b25f6c/src/server/ua_services_attribute.c#L394
you are looking for?!

Simple encryption in lua

I was wondering, what would be the easiest way to encrypt a message, into a 128-bit with a key. I wanted to code something on my personal computer, that would use LuaSocket, and based on what is sent to my PC, the computer executes X command. This is just something easy, and something for me to code, so I can remotely access my computer, from another computer. I want to make the script first require a password, before granting access to ANY command. But, if someone is spying on the connection, they can take the password, and abuse my PC. So, is there a simple way to securely communicate between MY PC, and the PC that is connecting with my PC (dunno much about encryption)? (somewhat-off-topic: how do you get LuaSocket to reply to the client? lua.org explains client-to-server, but how do you do server-to-client?)
how do you get LuaSocket to reply to the client?
The server obtains the request using client:receive and sends its response using client:send. Please note that even if the documentation calls the variable "client", it doesn't mean the client side of the connection. Instead it means the "connection to the client" from the server's point of view, returned by client:accept.
See http://w3.impa.br/~diego/software/luasocket/old/luasocket-2.0-beta/introduction.html

More than 1 client in a udp echo server

I have a UDP echo client and server program. As im trying to connect more than one client to connect to the server using different computers i'm getting a positive response , that is im being able to connect my server with more than one client.
So, my question is, when I break ctrl+c to break the server, I want to print the ip addresses of all the clients which are associated with the server at that time.
How do I do it? I know how to print the IP address when a single client is connected to a server, but how do I print for more than one client?
There aren't any build-in mechanism to do it. UDP is connectionless, so sockets don't "remember" who they communicated with.
To print all clients your server communicated with you need to keep track of them yourself. You'd probably need a set (you can find some open source implementations of sets in C if you don't want to build one yourself) or even a simple linked list might do, depending on your case. After each recvfrom, add the client to the set/list. After you're done processing each request, remove the client from the set/list.
Then you need to set up a handler to react to ^C. In it you just print the set/list.

Local Chat server in C using IPC

Hi Guys I need to write a chat server in C. It only needs to use IPC.
Could you help me on how to proceed on this. A skeleton code will help me a lot.
Write an echo server: a server that accepts one client, and repeats everything the client says back to it.
Expand this server to support multiple simultaneous connections.
Have the server echo to all connections.
Consider as commands some pattern of lines from clients -- an initial "/", say, and act on them (close the connection, name the connection, list connections, etc.) rather than echo them.
Prefix all echo'd text with the name of the client, with a default "Anonymous$N" and then the name set by a command from #4.
When receiving a new connection, have the server elicit a name from it before the server begins echoing text from it and acting on other commands.
And so on. As mentioned, Beej's Guide can help you get past #1 and #2.
EDIT: OK, you added the 'IPC' language. You can still use sockets for this over the loopback device, unless you've some special requirement that you think IPC covers. You can also use UNIX domain sockets - named pipes. perlipc discusses them with a short example, and you can continue to e.g. the GNU C library manual.

Resources