Thread: how would I go about doing something like this?

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    17

    how would I go about doing something like this?

    From a C program running from a local system, when it first executes, I would like check its ID against a text file located on a remote FTP site or a website. At that FTP site, there will be a text file that looks something like this:


    ID_NUMBER ALLOW

    12345 yes
    11111 no
    22222 yes


    So let's say the user executes this executable program from location 1. His PC's ID is designated as 12345. The C program checks my FTP site, and ID 12345 is allowed to execute. The executable program has permission, and it just continues at that location 1.

    At location 2, that PC's ID is designated as, let's say, 11111. As the executable C program runs, it checks that text file on my FTP site, and sees that ID 11111 does not have permission (or that ID is not on the list), the C program simply gives an error message to the user, and then, stops.

    How would I go about implementing something like this? Thanks.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,337
    You could use libcurl API calls to get the file and parse it. About 50 lines of code.
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Well for starters you need a way to get the "ID". Is it stored in some file on the (local) computer? In the registry (Windows)?

    After that you need to connect to an FTP server and download the file that contains the list of "permissions". If you dont have any restrictions, then use some FTP library that exists. Otherwise, you have to create your own FTP client. These are actually not very difficult (especially if its for some special purpose/ad hoc thing like this).

    Start with the first thing Ive mentioned here, and let us know the details of any problems that come up. After that, find an FTP library (if allowed), set it up, read examples that must have come with it, or learn about the basics of FTP protocol if you have to write your own. Let us know what the problems are.

  4. #4
    Registered User
    Join Date
    Jul 2009
    Posts
    17
    Thank your for your response.

    I've got the ID part done already. I just need to know how, from the local computer, the user can read that file remotely. This would be very simple if the file is on the local C drive.

    But, I want the file to locate on my FTP server so that I have control as to when that program will expire. And also, if I were to edit that text file from my FTP server, the user then can execute that program again. If the file resides locally, that user can access the file and change it himself.

  5. #5
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    As I mentioned, you need to understand how FTP works. Also, as I mentioned, you need to find out if you can use some FTP library or if you have to write a simple FTP client yourself (which isnt too difficult, for your specific requirement).

    If you can use an existing library, then search around and do it--it should be quite straightforward. If you run into problems with some library you find and try, then give us all relevant details so we have a "problem" to work with.

    Again, as I mentioned, if you have to write your own, then the first place to start is to learn the basics of the FTP protocol. I just mean the basics, as your specific requirement only needs that. You can use "telnet" to see the "internals" of how FTP works. A quick search brought this link that seems decent: » Understanding FTP using raw FTP commands and telnet - PHP, Web and IT stuff. In your C program, you would use a socket to connect to the FTP server on the appropriate port (standard is 21). After you have the socket connection, you basically write/read to the socket, the same way that using "telnet" does, as you can see from the in/output in that link.

    One of the big differences between reading that link and what you do in the code, is to handle delimiters, i.e. the symbol that represents you and the server saying "Im done sending information" or "Im done receiving information"). You can read about FTP (Wikipedia or elsewhere) to see what the delimiter is, I think its something like "\r\n\r\n", though I dont remember off the top of my head.

    The other big difference between just reading that link and implementing the code for it, is that when you send/receive files, they are done using a different port (I think 20 by default). So you have 2 ports open at the same time, one (21) for communicating with the server, another one (20) for the file transfers. Normally this sort of thing requires multiple threads. However, due to your basic requirement, you can just use the same thread, as you know exactly whats going to happen.

    I think this should help for starting. When you run into a problem, let us know, giving us all relevant details.

Popular pages Recent additions subscribe to a feed