sciClops - Updating via FTP

Recap
The last week was able to simply copy files from the host PC to the CF via a USB card reader. Then after placing that CF back in the TS-7200 and re-booting it, I was able to copy over that file to the Linux root structure.

Expectations
Instead of only being able to edit html files using vi, as I was limited to the previous week, I am now able to copy files over using the CF card. It would be even more beneficial to be able to transfer files using FTP and automatically update the existing files with files found on the host computer. This week's the goal, just as was last week's, is to be able to log onto the server and perform file transfers. I am going to set up the FTP server to perform the following:
1. Use FTP to download a file back to the PC from the server via the network.
2. Send a file to the server using FTP.
3. Generate a web page that will update itself with a page of the user's choosing.

Results
Setting up the FTP session
The ftp session was set up using Mozilla. I entered the address ftp://192.168.2.50 into the address bar and waited for the failure message. The server will attempt to login you in as an anonymous user, and fail (because I didn't set up anonymous users). I then right clicked and selected "Login As..." I entered my user name and password. I was able to see the files in my user's home directory. Dragging and dropping transfered the files from my host desktop to the home directory on the server. I later found out that the proper way to access an FTP server is to use your login name as part of the address. i.e. ftp://username@192.168.2.50

FTP Transfers

I transfered two files. One was a shell script that would echo environment variables in the form of an HTML file, and the other was an HTML file what I was going to use to invoke the shell script. I then logged into the server using the serial console as the root and moved the files to their appropriate folder.

The HTML file which I placed in the /www/apache/htdocs folder:

<html>

<head>
<title>Test Page</title>
</head>

<body>

<p align=center>Test Page</b></p>
<p>This is a test page being from the sciClops server.</p>

<form action="http://192.168.2.50/cgi-bin/update" method="GET">
<input type="file" name="file">
<input type="submit" value="Update">
</form>

</body>

</html>

The shell script, which I placed in the /www/apache/cgi-bin folder:

#!/bin/sh
echo "Content-type: text/html

<head>
<title> CGI Tutorial: Environment variables script</title>
</head>
<body>

<hr>
<h1> Environment variables script</h1>
<hr>

<p>
Here are the environment variables that this CGI script has been
called with.

<p>
<hr>
<pre>"

/usr/bin/env

echo "</pre><hr>
</body>"

File Permissions

I had trouble executing the files because they were transfered from a windows environment. Their end of line (EOL) characters and their file permissions were not set up. I manually removed the ^M at the end of every line using vi (I didn't bother learning the built in search/replace commands). I changed the permissions to make make the user have full permissions, and group and all have readable and executable permission using:

chmod 755 file.name

I must admit that I omitted the #!/bin/sh in the script file and that may have been the reason that the script did work at first, having nothing to do with the EOL characters.

Testing
I tested the work I did so far by opening up a web browser on the host and navigating to the update.htm at the address http://192.168.2.50/update.htm
The page opened properly, the file dialog worked, and the update button executed the shell script and opened the Environment Variables page.

What's Next

The final task for this week was to update/replace a web page that the server launches using an update web page. Using what was established so far, the update button on the update web page needs to launch a shell script that will parse the sent file, save it on the server (at the appropriate location), and rename it to index.htm.

Due to the limitation on the number of characters when using the method "GET" in the HTML form, I need to transfer the file using the "POST" method. Unfortunately parsing the received file requires knowledge of the Perl language. A task that will have to be left for next week.

Posted In

Post new comment

The content of this field is kept private and will not be shown publicly.