Search What Do You Want In here

Custom Search
Showing posts with label Using. Show all posts
Showing posts with label Using. Show all posts

Sunday, September 26, 2010

Using Perl and Regular Expressions to Process HTML Files - Part 3


In Part 1 we had a quick look at what Perl and regular expressions are, and introduced the idea of using them to process HTML files. In Part 2 we developed a Perl script to process a single HTML file. In this part we'll look at how to process multiple files.

The script we looked at in Part 2 (script1.pl - repeated below for convenience) has one major drawback, making it unusable in real terms: the name of the web page (HTML file) that the script processes is hard coded into the script itself. For the script to be useful, we need to be able to run it on any web page. Changing the script so that it can do this is fairly straightforward.

Below, I've given two scripts: script1.pl, which was our original script from Part 2, and script2.pl, which is a new script that will process a list of files.

Note: Due to display considerations, in the example code shown in this article, square brackets '[..]' are used in HTML/script tags instead of angle brackets ''.

script1.pl

1 open (IN, "file1.htm");

2 open (OUT, ">new_file1.htm");

3 while ($line = [IN]) {

4 $line =~ s/[h1]/[h1 class="big"]/;

5 (print OUT $line);

6 }

7 close (IN);

8 close (OUT);

script2.pl

1 foreach $file (@ARGV) {

2 rename $file, "$file.bak";

3 open (IN, "$file");

5 while ($line = [IN]) {

6 $line =~ s/[h1]/[h1 class="big"]/;

7 (print OUT $line);

8 }

9 close IN;

10 close OUT;

11 }

Before looking at each line of the script in detail, let's just quickly establish what script2.pl does. Well, it processes one or more files entered at the command line prompt (for example, the MS-DOS prompt) and then, for each file entered, the script initially makes a backup copy before changing every occurrence of [h1] to [h1 class="big"].

A few quick definitions:

Variable

A temporary storage place for a value. In the above script, $file is a variable. The filename file1.htm, which will be entered at the command line prompt, is a value that will be temporarily stored in that variable when the script is run.

Array

A storage place for a list of values.

Let's take a look at each line of script2.pl.

Line 1

This line enables one or more files to be entered at the command line and processed by the script. We only have one file, 'file1.htm', so when we run the script we'll only enter one file to be processed.

Line 2

This line makes a backup copy of each file before processing it. So, for 'file1.htm', the backup file would be 'file1.htm.bak'.

Line 3

This line opens a filehandle for the file being processed. Part 2 of this series of articles gives more information about filehandles.

Line 4

This line opens another filehandle, but this time for the output from the script.

Note: file1.htm.bak will contain the contents of the file from before the script is run. file1.htm will contain the updated contents, that's to say, the output from the script.

Line 5

This line sets up a loop in which each line in the input file (the file being processed) will be examined individually.

Line 6

This is the regular expression. It searches for one occurrence of [h1] on each line of the input file and, if it finds one, changes it to [h1 class="big"].

See Part 2 for a full description of the actual regular expression.

Line 7

This line takes the contents of the $line variable and, via the OUT file handle, writes the line to the output file.

Line 8

This line closes the 'while' loop. The loop is repeated until all the lines in the file currently being processed have been examined.

Lines 9 and 10

These two lines close the two file handles that have been used in the script.

Line 11

This line closes the 'foreach' loop. The loop is repeated until all the files entered at the command line prompt have been processed.

Running the script

To run the script, at the command line type:

C:>perl script2.pl file1.htm

If the script executes successfully, a new file should be created called file1.htm.bak, which is a backup of the orginal file (ie before it was processed). A new version of file1.htm should also have been produced, containing the modified [h1] tag.

In Part 4 we'll look at an alternative way of inputting/selecting files for processing.








About the Author: John Dixon is a web developer working through his own company John Dixon Technology Limited The company also develops and supplies a free accounting-bookkeeping software tool called Earnings Tracker. The company's web site contains various articles, tutorials, news feeds, and a finance and business blog.


Thursday, September 23, 2010

Using a PHP File Manager


A PHP file manager is an advanced tool for managing file systems and it is available on a single file. This software is very useful for managing all kinds of directories and files, which are available on a FTP server or your web server. The same software has many features and functions. It is helpful in renaming, creating, uploading, and deleting directories. With its help you can edit, rename, download, delete, as well as search files. You can even change directory and file permissions.

A php file manager works quite well with FTP connections. However, you should bear in mind that if you fail to arrange an FTP connection in your configuration, then the php file manager would be using the local file system. If that happens then you will be able to access only the directories as well as files for which the PHP has read permission, at least. If you wish to upload, rename edit, or delete certain files, or change the file permissions then PHP will also have the write permission for the same files or directories.

You can use PHP file manager as a stand-alone software. However, you will also find that it is quite easy to integrate the file manager within your own website. When you download the manager, you can go through the usage section to find out the way in which you can do it. The updated version or the latest version of the PHP file manager has many useful features. It works properly with FTP servers, that is UNIX and Windows, and even with the local file system. It has the ability to support multiple languages. You can adapt it by modification of CSS file and configuration file, with ease. It is very easy to integrate it with your website and it can support icon view and detailed view.

The other features of the PHP file manager are also very good. The file manager has a built-in editor for all kinds of text files. It has a built-in preview with thumbnails for images. The built-in action log is also helpful. Features like integrated directory and file search make it user friendly. The file management tool has the capacity to support automatic setting of various permissions while uploading files or creating new directories. It can also support automatic modification made to lowercase or to replace spaces of filenames for different uploaded as well as downloaded files.

With the help of PHP file manager, you can upload up to 10 files at a time. It maintains automatic backup creation while uploading files. It can support password protection for login. Another thing that the file manager supports is hiding of files with arbitrary extensions and system files.

A Php File Manager is a form of modern tool that is useful for the management of file systems and you can get it on one file. The software comes very handy for managing different directories as well as files, available on either a FTP server or even your web server.








Steve Callen has been contributing to leading magazines for the past 10 years. He's also an accredited researcher on the subject for leading research institutes in the US.



This post was made using the Auto Blogging Software from WebMagnates.org This line will not appear when posts are made after activating the software to full version.

Using Free File Hosting Services to Store Files Online

File hosting is a popularly used method for keeping files ready for access anywhere, anytime, without the requirement for a usb drive, hard drive or any removable storage. You have a huge file space of around 1 MB - 300 MB large enough to accommodate lots of pictures, documents, MP3s, documents or any file. You can get your files downloaded by any person with whom you are willing to share.
With file hosting, you can keep your important files online and conveniently access them from any where in the world. File hosting also enables you to share the files with your friends. By availing the free file hosting services, you will get a large space to keep files and document that you require to be shared online with others. Free web space allows you to store the files and free bandwidth enables you to share your files. The file hosting and sharing services earn their revenue by placing advertisements for the visitors of the file sharing site.
Some file hosting services offer you revenue sharing program while using their free services. Under this program, you will get the payment when some one visits your web site for downloading your files. File hosting companies allow you to upload your files, which can later be downloaded by using a premium account or free account. By having a premium account you can download contents and files of a large database that include movies, videos, songs and ebooks etc..
By opting for free file hosting, you eliminate the limitations imposed by email services. Your contacts can download the files uploaded by you by using a link whenever they need. However, for the safety and security of your files, you have to read and understand the terms of the free file hosting services. In the recent years, the hosting services have become very popular due to its increase in demand. Webmasters are using file hosting services to save the cost of disk space as well as bandwidth. To prevent any possible illegal actions, the terms and policies of various file hosting services do not permit uploading of copyrighted materials and documents.
A premium account with a file hosting website provides you more benefits than a free file hosting website. Some of the important benefits are: - download with maximum feed using super fast servers, use of downloading managers like Flashget, DAP and IDM for downloading files, immediate downloading of files without any waiting time, direct download links, extra server slots, downloading without any file size limit and back up of files. Above all, you get a dedicated support from a team of staff who are ready to assist you.
Free file hosting services are very useful for webmasters to store the data in a more efficient manner and save them from any disaster. With so many file hosting and sharing services available for you, you have enough free space for your favorite songs and home videos that you may get while surfing the internet. With a large available free space you are at liberty to store and use whatever you like.







Article by Marx Marx in conjunction with: Turbo UploadThe Premier Free File Hosting and Sharing Service - Sign Up for One of Our Free Unlimted Bandwidth and Downloads Accounts with 2GB of File Storage Space

Wednesday, September 22, 2010

Dreamweaver: How to Publish Files Using FTP

Before you can publish in Dreamweaver, you must set up a "home base" folder where your website will live on the local hard drive of your computer. Once this is in place, you can use Dreamweaver's FTP feature to "get" and "put" the HTML files from your local folder to the remote server. Here's how to set it up for a BASIC website that does not include PHP, .asp or any "dynamic" elements.
Open Dreamweaver.
Go to the top menu and click SITE, then NEW SITE
The prompt will ask you for a name. Name it "Whatever Your Site's Name Is" (you can space this - it's like a title bar, not a domain.)
Next Prompt: Do you want to work with a server technology?
Your Answer: NO
Next Prompt, Question 1: How do you want to work with your files?
Your Answer: Option 1
Question 2: Where on your computer do you want to store your files?
Your Answer: (Here, you will set up a folder hierarchy. Your heirarchy might be, C:/Your Websites/Name of Website
Next Prompt: How do you connect to your remote server?
Your Answer: FTP
Now it will ask you the following questions:
What is the hostname or FT address of your Web server?
Your Answer: This will vary. Typically, it's ftp.whateveryourwebsitenameis.com (starts with ftp, a period, and then a domain name dot-com. The domain name could be your own domain name, or it may also be the domain name of your hosting provider. You may want to search for the term 'FTP' in your host's help instructions so you know exactly what address to enter here.)
What folder on your server do you want to store your files in?
Your Answer: typically the answer to this is htdocs, but you have to figure out where your main HTML files are stored on your server. (I know that in Earthlink the folder is called webdocs).
What is your FTP login:
Your Answer: whatever your website login is
What is your FTP password:
Your Answer: whatever your password is
Now check off "save" and then click TEST CONNECTION to make sure you're hooked up. If you can't connect, recheck the above information and repeat the process.
Next Prompt: Do you want to enable checkin and checkout?

Your Answer: NO
(This is up to you. If you have multiple designers on your team, then checkin and checkout could be a good way of preventing file versions accidentally overriding each other. If you work alone, just say NO.)
Note:
If you screw this up for some reason or want to change anything, go back up to the top menu, click SITES again and select EDIT. you'll see the name of your website (whatever you named it in Step 1) listed and you can repeat this same process.
To use the FTP in Dreamweaver, just go to the far right hand window where it says DESIGN, CODE, APPLICATION, FILES all stacked vertically. Hit the arrow where FILES is located to open up the little FILES window.
Note: if you don't see any far right window, you may have chosen the alternate view when you first launched the program. In this case, go to the TOP MENU BAR and click SITE and then SITE FILES. A floating window should open up that you can drag anywhere beside your main window.
In the FILES window, you'll see a little pulldown menu where you can opt to view your server files.
Next to that pulldown is another pulldown menu that says REMOTE VIEW. By default, you're looking at the server (as opposed to your local computer folders, which is another choice in this pulldown).
Just beneath the word FILE in that FTP window, you see a little icon that looks like a plug with a black dot next to it (far left). Click that and it'll "connect" you and the dot will turn green, for "GO Dreamweaver!"
To open a file from your desktop, mouse away from the FTP window and go to the *usual* place in any program where you'd open a file. (Top menu bar, far left, FILE.)
Open the file from the folder where it's located on your computer. Edit the file.
When you're done editing the file, go back to the FTP window on the right, that you just set up. Make sure you're connected (that dot next to the plug doohickey should be green. If it's black, click the plug icon again to connect).
To transfer the file from your local desktop to the remote server, do this:
Mouse away from the FTP window again, and back to your open file. Focus your gaze TOP CENTER. Next to the TITLE bar there are two arrows, a green "down arrow" and a blue "up arrow."

To PUT the file on the remote FTP server, click the BLUE UP ARROW.
(The blue UP arrow stands for PUT or PUBLISH from your computer to FTP server)
(The green DOWN arrow stands for GET or retrieve your file from the FTP server to your computer)
Later on, you may want to open the file directly from the FTP server and edit it.
So, go to the FTP window and click the icon to connect to your server again. The list of files should appear.
Find the name of the file you want to edit, and while still in that mini File window, click the name of the file once (to highlight). Then click 'FILE' and 'OPEN'. (this is all done in the little FTP window, not the main window).
Now your file will open up in the main (big) window. Edit it, and then click that BLUE ARROW by the center TITLE BAR to PUT or publish it again.
NOTE: if you click the blue arrow located in the little FTP window, it will PUT the ENTIRE SITE from your desktop to your server.
If you've already edited and put some files but not others, this will mess your stuff up royally. Why?
Because it'll take the files from your computer and replace the "most updated files on your remote server" with the old ones from your local folder, thereby deleting your work. I have done this by accident and it is no fun.
If you know that all the files on your server are the *correct* ones but the ones on your desktop are the *old* ones, you can *get* the files from the server by clicking the GREEN DOWN arrow in the little FTP window on the right.
This will replace every file on your hard drive with the same named files from your server.
If you royally mess up something, but as you remember it, the last file that you PUT (or published) is still live on the web, you can type in that file name in your internet browser and then do a VIEW SOURCE, copy the HTML code, and paste that back into the file on your hard drive, Save, and then PUT it again.
Generally, it's a good idea to work from your local folders and then PUT the entire site (in the FTP window) all at once. But I am a jerk and I don't do it that way.
Good luck, and happy FTPing, getting and putting!
Copyright 2006 Dina Giolitto, Wordfeeder.com Copywriting and Marketing Services for the Web







Liked this article? Have more of the same emailed to your inbox each month. Sign up for the Copywriting and Marketing Ezine from Dina at Wordfeeder.com and learn to write search engine friendly web copy and market your web based business for free.

File Compare - Using File Compare Software To Improve Productivity

For finding the difference between two files, there is need for matching two files and the operation for it is termed as file compare. File compare can be simply termed as comparing of files or handling of files. Ever since the computers come into force, the need for comparing files arised. So the file comparing programs were found out in those days itself. In early days it came out for command line utilities and then soon for graphics based applications. For problem troubleshooting as well as for tracking of the changes, while writing programs, file compare programs are very essential. There are programs which can compare more than two files and that in very short period. The files may be of text format or any other format.
The functions of a file compare tool. In file compare there is compare function which compares the contents of two or more sources and contents might be file handle or file. Export of there files or file handles are done by default from file compare. For file compare there is a synonym i.e. cmp and it is exported by request only from file compare. Each line in the two files is compared line by line, by compare_ text. When the difference is detected the compare_ text stops. A third argument which is optional is accepted by compare _text {}.For line comparison Compare_text{} is a CODE reference. When the two lines are advised as equal, Compare_text{} returns as zero. If there is advice of inequality between the two files then the file compare and related functions will return 1.If there is an error then the return will be -1.These are very basic facts. And with too may programs with advanced features there are drastic changes in features.
Now a day file compare programs are not just meant for comparing files as well as folders, but also for visualization of code changes, validation of the data copies, syncing of the directories, comparison of the output of programs, updating, comparison of source code versions, supports certain features, synchronization of fragments which differs, multilingual interface, highlighting of syntax for different languages, file management, edition, display and many more features depending on the programs.
The latest trends and software. In new age file compare programmes tools for merging and visual files comparison which helps in comparison of different versions of text file which is same. Color coded comparison of files nearer to each other helps in easier understanding of difference in files in one glimpse. Printed reports of file comparison are possible these days. Usage of multiple platforms is significant as there will be need for dealing different operations of files of DOS, Mac systems, Windows, UNIX etc.
One File compare is md5 to GUI front end command based on UNIX program. Some file compare programs are free versions so can be downloadable easily. So as per the sophistication of the files for comparison the right program has to be chosen. In this highly competitive software industry file compare is a boost for the programmer who tries for excellence.







If you are interested in file compare, check this web-site to learn more about file comparison.

Tuesday, September 21, 2010

Website Protection and Security Using File and Directory CHMOD

A variety of files and directories in your website need to be given the correct permissions to work properly. Giving permissions to files or directories in the Unix world is called CHMOD (change mode). Chmod is a Unix command that lets permission levels be assigned to each file or directory. The proper CHMOD is also needed to help you with your website protection and security. As you will see later in this document, you can use your FTP client to change the file permissions in order to protect your files.
Every file or folder in UNIX has access permissions. There are three types of permissions (what allowed to do with a file):
1) read access
2) write access
3) execute access
These specific permissions apply as follows:
Read: The read permission, which grants the ability to read a file. When set for a directory, this permission grants the ability to read the names of files in the directory (but not to find out any further information about them, including file type, size, ownership, permissions, etc.)
Write: The write permission, which grants the ability to modify a file. When set for a directory, this permission grants the ability to modify entries in the directory. This includes creating files, deleting files, and renaming files.
Execute: The execute permission, which grants the ability to execute a file. This permission must be set for executable binaries (for example, a compiled c++ program) or shell scripts (for example, a Perl program) in order to allow the operating system to run them. When set for a directory, this permission grants the ability to traverse its tree in order to access files or subdirectories, but not see files inside the directory (unless read is set
When a permission is not set, the rights it would grant are denied. Files created within a directory will not necessarily have the same permissions as that directory.
Access permissions for files and folders mean different things from the user standpoint. Below shows the difference.
Read Access For File: On a regular file, the read permission bit means the file can be opened and read
Read Access For Directory: On a directory, the read permission means you can list the contents of the directory.
Write Access For File: On a regular file, this means you can modify the file, aka, write new data to the file, change its contents
Write Access For Directory: In the case of a directory, the write permission means you can add, remove, and rename files in the directory. This means that if a file has the write permission bit, you are allowed to modify the file's contents, but you're allowed to rename or delete the file only if the permissions of the file's directory allow you to do so
Execute Access For File: In the case of a regular file, this means you can execute the file as a program or a shell script
Execute Access For Directory: On a directory, the execute permission (also called the "search bit") allows you to access files in the directory and enter it, with the cd command, for example. However, note that although the execute bit lets you enter the directory, you're not allowed to list its contents, unless you also have the read permissions to that directory
Every file on your Linux system, including directories, is owned by a specific user and group. Therefore, file permissions are defined separately for users, groups, and others.
Permissions are defined for three types of users:
1) the owner of the file
2) the group that the owner belongs to
3) other users
User Type - USER(u): The username of the person who owns the file. By default, the user who creates the file will become its owner.
User Type - GROUP(g): The usergroup that owns the file. All users who belong into the group that owns the file will have the same access permissions to the file. This is useful if, for example, you have a project that requires a bunch of different users to be able to access certain files, while others can't. In that case, you'll add all the users into the same group, make sure the required files are owned by that group, and set the file's group permissions accordingly.
User Type - OTHER(o): A user who isn't the owner of the file and doesn't belong in the same group the file does. In other words, if you set a permission for the "other" category, it will affect everyone else by default. For this reason, people often talk about setting the "world" permission bit when they mean setting the permissions for "other."
The mode number consists of three octal digits, n1n2n3, representing the access allowed for yourself, for your group (other users set-up on your account), and for everyone else. The value of each digit represents the type of access that is allowed.
Each digit in the mode parameter represents the permissions for a user or a class of users. The first digit corresponds to the owner of the file. The second digit corresponds to the file's group. The final digit corresponds to everybody else.
We can also say that the first digit, n1, on the left, stands for the owner of the file or directory. The middle digit, n2, represents the group who owns the file or directory. The last digit, n3, represents the rest of the world.
Octal---Digit---Permission
000------ 0 --- no permissions enabled
001------ 1 --- execute permission enabled
010------ 2 --- write permission enabled
011------ 3 --- write and execute are both enabled
100------ 4 --- read persmission enabled
101------ 5 --- read and execute are both enabled
110------ 6 --- read and write are both enabled
111------ 7 --- read, write and execute are all enabled
We see from above table that:
1) read is given a value of 4
2) write is given a value of 2
3) execute is given a value of 1
This then is translated by adding the values together for each of the groups of permissions.
For example, let us say the CHMOD is n1n2n3 = 755 = user/group/other; what does this mean:
i) user can read (4), write (2) and execute (1): 4 + 2 + 1 = 7
ii) group can read (4) and execute (1): 4 + 0 + 1 = 5
iii) others can read (4) and execute (1): 4 + 0 + 1 = 5
If the group had the same permissions as the user then we would have 775.
Instead of numbers for the mode, we could also have letters as follows:
1) read = r (4)
2) write = w (2)
3) execute = x (1)
4) not enabled = - (0)
We can then make 755 = rwx r-x r-x
where:
user = rwx
group = r-x
other = r-x
If we had 765 then this would be the same as rwx rw- r-x
You can also see users defined by letters as follows:
1) user = u
2) group = g
3) others = o
4) everybody = a
Usually, only the file owner can change permissions.
Although a shell prompt in a Unix-like environment can be used to do this, an FTP client is often used for such task. Depending on the FTP client being used, CHMOD is usually available through menus or by simply clicking the right mouse button when hovering over a file or directory and choosing the chmod/property option. To set the permissions check the properties or enter the corresponding chmod numbers in the dialogue box.
For more information you can visit the following:
http://www.websiteprotection.net
On a web server, files are usually set to 644. This indicates that the file owner can read and write to the file, while everyone else can only read it. Directories are commonly set to 755. This indicates that the directory owner has full control, while everyone else can read and execute the files within it.
You should take care in setting files CHMOD 777. This basically means anyone can read/write/execute/search the file/directory. In this situation you are leaving your web pages open to the world and making it easy for people to hack your website.







Joseph Schembri has over 10 years of production, logistics and management skills with multi-faceted manufacturing experience. He has also written many ebooks that are practical, easy, but thorough with step by step advice on website security protection and internet niche marketing. They are written in a language that you can understand with all the extra nice to have stuff stripped away. http://www.nichemarketingsecrets.net

Search What Do You Want In Here...

Custom Search