Editing HTML with FTP access


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Editing HTML with FTP access
# 1  
Old 08-21-2014
Editing HTML with FTP access

Hello, I've got a similar problem. I want to add some lines before the ending of the <head> tags. How can I do that?
Example.
HTML Code:
<head>
 <some website stuff here>
 <My stuff>
<head>
I'd like to do that automatically with ftp. Is it possible to activate a sort of syncing in order to update changed files? And I'd also like to prevent adding <my stuff> in files that already have <my stuff>.
Thank you!

Last edited by rbatte1; 08-21-2014 at 12:17 PM.. Reason: Added HTML & ICODE tags
# 2  
Old 08-21-2014
Please post your question in another thread.

FTP is very simple and stupid. It can't edit files. You could download them, edit them, and upload them back.
# 3  
Old 08-21-2014
Yes, I know that ftp is stupid and it can't edit files. I was looking for a sort of ftp syncing solution for modified files, a bit like dropbox. But my main question was, and remains: I want to add some lines before the ending of the <head> tags. How can I do that?
Example. HTML Code:
Code:
<head>
<some website stuff here>
 <My stuff>
<head>

I'd also like to prevent adding <my stuff> in files that already have <my stuff> .

Thank you.

Last edited by Corona688; 08-21-2014 at 01:27 PM..
# 4  
Old 08-21-2014
Split from This Thread.

Please use code tags for code, [code] stuff [/code]
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 08-21-2014
Hmmm. Keep a line like <!-- MY HEADER --> in your stuff so you can scan for it to tell if it's there. <!-- END MY HEADER --> would also be good in case you need to remove it later.

Code:
OLDIFS="$IFS"
IFS="/"

N=0

find /path/to/files -type f | while read FILEPATH
do
        set -- $FILEPATH # $1=path, $2=to, $3=files, $3=subdir, etc
        shift 3 # Discard 'path', 'to', 'files'
        DESTDIR="/home/username/public_html/"$* # /home/username/public_html/subdir/filename

        grep "<!-- MY HEADER -->" "$FILEPATH" && continue
        if [ ! -e "$NEWPATH" ] || [ "$FILEPATH" -nt "$NEWPATH" ]
        then
                awk -f newheader.awk header="/path/to/headerfile" "$FILEPATH" > "/tmp/$$-$N"
                echo "put \"/tmp/$$-$N\" \"$NEWPATH\""                
                let N=N+1
        fi
done > list-of-files-to-upload

ftp <<EOF
...

`cat list-of-files-to-upload`
...
EOF

rm -f /tmp/$$-*


I cannot guarantee that newhead.awk is bulletproof. Parsing XML is not trivial.
Code:
$ cat newhead.awk

BEGIN {
        FS=">"
        OFS=">"
        RS="<"
        ORS="<"
}

NR==1 { next } # The first "line" is blank when RS=<

/^[!?]/ { printf("%s", RS $0 ); next    }   # print XML specification junk

# Handle open-tags
match($0, /^[^\/ \r\n\t>]+/) {
        TAG=substr(toupper($0), RSTART, RLENGTH);
        TAGS=TAG "%" TAGS;
}

# Handle close-tags
/^[\/]/ {
        sub(/^\//, "", $1);
        sub("^.*" toupper($1) "%", "", TAGS);
        $1="/"$1
}

{       printf("<%s", $0);      } # Print everything

# Add extra stuff to HEAD section
TAGS ~ /^HEAD%/ {
        P=""
        printf("\n");
        while((getline < headerfile) > 0)
        {
                printf("%s%s", P, $0);
                P=RS;
        }
        printf("\n");
}

$


Last edited by Corona688; 08-21-2014 at 01:58 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Editing path in a HTML file using Perl

Hello I want to replace the path to which a hyperlink points to. I have a html file <TABLE BORDER CELLPADDING=7, border=0><TR><td>Jun-10-2013_03_19_07_AM</td><td>Ank_Insert_1</td><td><b>FAILED: 1</b></td><td><A ... (14 Replies)
Discussion started by: ankurk
14 Replies

2. Debian

Help request. FTP user to var/www/html

Hi all. I appologise this is my first post, I will gladly have a further look around to see if this has been posted elsewhere, but so far it has not, or it doesnt quite explain in full what I need. If anyone here can help me out, I would really appreciate this. I want to make sure I do this... (1 Reply)
Discussion started by: Pinkfloyd
1 Replies

3. Shell Programming and Scripting

editing single line in html file in perl script

Hi Folks, It is regarding the perl scripting. I have an html file(many files) which contains the below line in the body tag. <body> <P><STRONG><FONT face="comic sans ms,cursive,sans-serif"><EM>Hello</EM></FONT></STRONG></P> </body> Now I want to read that html file through perl... (3 Replies)
Discussion started by: giridhar276
3 Replies

4. Programming

Minor editing of mass HTML files

Hello, I'm manipulating a batch of about 2,000 HTML files. I just need to make some small changes, but to all the files at once. For example, I want to delete the lines that have "embed_music" in all the files, or change all instances of the word "Paragraph" to "Absatz". This is my... (2 Replies)
Discussion started by: pxalpine
2 Replies

5. AIX

ftp access without shell access

Hi all, I'm using AIX v 5.3 I want to create system users to access through ftp or sftp and restrict those users into specific directory and don't traverse the whole file system just to be restricted within a directory and don't get shell access . i don't want to use any other third party... (7 Replies)
Discussion started by: h@foorsa.biz
7 Replies

6. UNIX for Dummies Questions & Answers

FTP access

Folks; I'm working on building ACL for our Solaris 10 box. I'm going to use LDAP for authentication. We have a mounted drive on that server & users would like to be able to write to it. We need to restrict the write access to that mounted drive on the box to be only through FTP, so if they... (13 Replies)
Discussion started by: Katkota
13 Replies

7. UNIX for Advanced & Expert Users

which access right should set in my webpage index.html ?

I have a webpage, http://my.dns.com/~zp523/index.html, I want all people to have read and execute privileges. I want to extend it with execute privilege. Which command should be used in chmod? is it only give read(r) & execute(x) parameter in 'chmod ??? index.html' thk a lot!! (1 Reply)
Discussion started by: zp523444
1 Replies

8. UNIX for Dummies Questions & Answers

FTP Access

How to restrict ftp user to move to the parent directory of his home directory. Any suggestions will be appreciated. O.S Sun solaris Regards (3 Replies)
Discussion started by: sehgalniraj
3 Replies

9. Shell Programming and Scripting

Access shell scripts from HTML page

Hi, I need (have been asked/order/instructed) to migrate the access of a number of ksh scripts into a html/web page environment. Currently access is with the user logging onto a unix box and accessing the scripts that way. The users are not unix people so I have restricted the access solely to... (4 Replies)
Discussion started by: nhatch
4 Replies

10. UNIX for Dummies Questions & Answers

FTP user access

I created a user which I would like to have access only to FTP. I am able to get FTP to the machine with that user, but I only want him to have access to two directories, and no shell access. How can I accomplish this? Thanx, Aaron (1 Reply)
Discussion started by: Spetnik
1 Replies
Login or Register to Ask a Question