How can I connect to an FTP with C? - c

Well, I'm trying to do a simple script to check any updates in an application. To check this, the most simple way I found is to connect to the FTP (where have a file which says the last update) and compares X file with a Y file. If the Y file is outdated, the script should run an installer/updater. Can I do it with C? I mean, can I connect to an FTP using C?
I research but nothing helpful was found.
At least, why C? I actually don't know. Part cause it is the language that I have more affinity, part cause I think it's clean, I dunno. Just intuition. haha.
Hope I have been clear.
PS: Working on Windows.

Well, I found another way to do this with a Batch File. I'm connecting to the FTP using the script (ftp -s:commands.txt ip.ftp) and then I use a comparation to check the differences. The rest was simple. Thank you all.

Related

How to i make a .bat that targets a program and types in a text box

I have no idea where to start on this one. I have seen answers that are like this but I don't know how to format them for what I want. I just need to target the minecraft server while its open and close it by typing "stop" in the console. I have no code to show for but this will be in a other file so I can launch it and then have it close the program. btw I don't think I can use taskkill But anything will help ;) thankyou very much!
This is not possible using a batch file alone. There are two main ways to get input to another program in the system (in this case, java.exe):
Get your program to listen for a special signal. There are several administrative plugins for Minecraft which will run in the Java process and will do what you need.
Spoof user input to the program. In the case of a console app, you would probably use a SendKeys() based solution. See How to send input to the console as if the user is typing for some examples.
In the case of Minecraft, I think the first solution is going to be significantly easier, because the modding community has already supplied a number of solutions to this exact problem. #Frxstrem recommended mcrcon, which I suppose is as good a solution as any.
Most probably the console client you are using is scriptable and this is not good aproach.
Any way here's a sendKeys.bat. You can use it like:
call sendKeys.bat "Minecraft console title" "stop{enter}"
Batch files can't do this without calling out to something else; if you're going to call to something else, use AutoHotkey - that's what it's good at.
WinActivate "the title of the Minecraft server window"
https://www.autohotkey.com/docs/commands/WinActivate.htm
Send stop{Enter}
https://www.autohotkey.com/docs/commands/Send.htm

fatal error: call to undefined function mssql_connect() on mac osx lion 10.7.4

So, I can execute php scripts from the terminal, but when the script tries to connect to the database using mssql_connect(), I run into this problem. I have gone through almost all of the sources available for this problem. But, it seems like I have something different. I'm fairly new to Mac, but I have followed most of the steps like uncommenting
#LoadModule php5_module libexec/apache2/libphp5.so
from the httpd.conf file, turning on the web sharing under system preferences. However, I'm not sure if I need to uncomment php_mysql/(i).dll from the php.ini file as well, since I'm using ms sql and not my sql. Also, I do not seem to have php_mssql70.dll like it was suggested in one of the forums I ran into during my search. But, there are 2 lines in my .ini file that read
extension=php_pdo_mssql.dll
extension=php_pdo_mysql.dll \\Yes. They both read the same thing.
Can someone point me in the right direction please? I'm not sure if the information I gave is sufficient. But yes, I think I have read and tried to emulate 90% of the forums that claim to solve this problem.
NOTE: This post seemed quite close to what I am trying, given that the user is a noob at this. I haven't really set up PHP, Apache, etc by myself since I have only worked with Php and MySQL in school till now.
How to install/use php on mac v 10.7.2
Since you're not on Windows you need to ignore anyone mentioning anything containing '*.dll'.
Look for extensions.ini which should in the same folder as php.ini, or in a folder very close to it, and you should be able to enable it from there, it should be a .so file. If it is not already there then the extension is not installed at all. I have no idea how to add PHP extensions on OSX, though. :I

Run GUI from batch file is unprofessional?

I recently released a software to our customer, it will be installed on one machine at one location and maybe later at two other locations. It is a prototype and has to be tested.
This is a compiled Matlab GUI which runs scanning, does some image analysis and produces report. All is fine here. But I've got a complaint that batch-file I use is a thing from past DOS times, should not be used and looks unprofessional... Currently, the user should set up one path in batch file before the first use and then always run batch file. This bat-file kills some processes to avoid conflicts, including any running instances of the GUI, sets the path for results and runs the GUI. I proposed them to create a shortcut to this bat-file with a nice logo (such that they don't see the .bat extension ;)), but they are still unhappy.
What to do is probably not the main question here - client is always right and I should remove .bat somehow to make them happy. But is it really so unprofessional to release technical, not mass software using bat-files? Or is it just one person's opinion?
Personally I think if you already have a GUI, then use that to do the pre-processing. There is nothing wrong with using batch files, but using one when you have a GUI doesn't seem like the best way to do it.
Alternatively create a GUI with the same look as the main program to ask the user for the details it needs. For me it's not about professionalism, but how easy it is for the user to do what they need to do.
I see nothing wrong with using a batch file for small projects (especially during the testing phase if that is easier for you and delivers something to the client quicker). However, depending on the size of the project, it is nice to have an EXE to deliver to the client with a proper icon and what not.
I would agree with the customer that an EXE looks more professional. Whether it is or not... I'm not sure. The .bat files just seem a little slapped together whether that is true or not.
I would say this is similar to when people call PHP programs scripts because a lot of the times they are simple scirpts. But, then there are frameworks out there like Cake and Kohanna that are more than what someone would typically classify as a script but, since it's PHP there is still that connotation.
A batch file is not unprofessional. The batch "language" has disadvantages and outright problems (error handling!!) but it gets the job done and that's the point.
The problem is that it shows the internals of the program and some people are scared by this. They don't want to see anything like this and so try to find a disapproving label. The quickest solution is to hide the batch file behind a "vanity cover", or in this case an exe that hides the working from terrified eyes.
One simple possibility is to use an self-extracting zip file eg: http://www.7zsfx.info/en/

edit the etc\hosts file

Using C or a bat file, I'm trying to edit the file hosts file from c:\Windows\System32\drivers\etc but I can;t bc it is write protected.
Can you tell me what can i do?
The program modifying the host file needs to run as Administrator
Can you tell me what can i do?
Yes. Get the Administrator password or find another way to solve your problem.
If you describe what is your problem (rather than your issue on a possible solution) maybe we can figure a different (working) solution.
Open the file from VS code. VS code it self will show a dialog box. Confirm it.

Is it a good way to use system() for database scripts from C?

I was searching for connecting to database from C program. But I thought the ODBC connections, logon and all need some libraries. Also I am having a minimal compiler like Tiny C Compiler which is very fast. I do not want to use any ODBC logic etc which is needed to connect and query the database.
So I am using a method which is as follows.
I use a bteq script (teradata) which will have login, query, logoff commands in that. (FYI bteq is a command line database utility. You can use it similar to mysql.exe in command prompt by going to the path of the exe. You can replace bteq with mysql.exe etc). And I use
system("bteq <myscript.txt >out.txt");
myscript.txt will be like the following..
.logon boxname/user,password;
select date;
.logoff;
The above script will logon to the database and query date (you can change the query and write script according to your database engine and your needs) and give output into out.txt.
Now I will parse the out.txt for the row X column I want using fgetc,fscanf or fgets.
And use the data for checking and send a mail using PHP on any server
system("c:/server/php/php.exe sendmail.php");. We can do the same for many a database engines like mysql, .. etc through a simple C program.
Now my question is Is there any flaw in the above method.
If it is then how can I overcome it. I am asking this question because I think this method is unconventional. Please give your opinions on this method. I don't bother about time needed for execution, RAM used, performance issues etc. I know system() function is time consuming which is not my concern anyway. I also developed specific functions to access query results (similar to accessing a flat file). Please tell me if you have any improvements to this method. If you get to know of any flaws in this please let me know. All kinds of suggestions are welcome.
My environment is : teradata bteq on windows with Tiny C Compiler
This is a perfectly fine way to access an external database, as long as your needs are simple. If you already know about the performance and memory implications of doing this, then there's not much more to say.
The method is fine: it's great to decouple the db subsystem and the parser subsystem by implementing them in an appropriate language.
There's just this tiny little thing - but I may be mistaken because I'm not familiar with bteq: the program will need a bteq script installed in the execution folder; this script will contain username and password. If those aren't encripted in some way, there might be a security flaw.
I wouldn't recommend this if your calling code is running setuid or setgid, but in that case you could use one of the exec() functions instead. (There are a few other considerations you may wish to take into account, all detailed in man 3 system.)

Resources