- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Yet Another FTP Script
Categories
Company
Local Language
Forums
Discussions
Knowledge Base
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2006 04:37 AM
01-13-2006 04:37 AM
Yet Another FTP Script
#!/bin/sh
if [ -s /some/file ]
then
ftp -n host <
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2006 04:57 AM
01-13-2006 04:57 AM
Re: Yet Another FTP Script
One way around this would be to retrieve the *remote* file's timestamp in an ftp session with 'modtime'. See the manpages for 'ftp'.
What you will have returned is something like:
/tmp/myfile 01/13/2006 17:40:06 GMT
You could then create a reference file whose modification timestamp matches the remote file timestamp and then compare the two file's timestamps with the 'test' operators ('-ot' or '-nt'). See the manpages for 'sh-posix'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2006 05:17 AM
01-13-2006 05:17 AM
Re: Yet Another FTP Script
By the way, creating your reference file from the date and time string returned is merely a matter of parsing the date and time fields and applying them to a 'touch' command to create a reference file. Since your local time probably differs from the GMT (UTC) returned, and you want your timestamps synchronized to equivalent timezones for comparsion, do something like:
[ ftp modtime returned: 01/13/2006 17:40:06 GMT ]
# TZ=GMT UNIX95= touch -amt 01131740 /tmp/ref
Since, in my case, I am UTC-5 hours or EST, the remote file I queried was really modified at 12:40 EST. An 'ls -l' after the 'touch' will show the corrected, local timestamp of the file for proper comparison.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2006 05:29 AM
01-13-2006 05:29 AM
Re: Yet Another FTP Script
Rsync only copy newer files if you configure to do that.
With ssh you can check the file dates and with scp you can transfer the files that you need.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2006 05:31 AM
01-13-2006 05:31 AM
Re: Yet Another FTP Script
#!/bin/sh
if [ -s /some/file ]
then
(
echo "quote user username"
echo "quote pass password"
echo "lcd /usr/tmp"
echo "binary"
echo "get file /tmp/file_remote"
O=$(find . -name "file" -newer /tmp/file_remote | wc -l)
if [ $0 -gt 0 ]
then
echo "put file"
fi
echo "quit"
) | ftp -n host
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2006 05:42 AM
01-13-2006 05:42 AM
Re: Yet Another FTP Script
The 'newer' option of 'ftp' is a variation of 'get'. Hence, the reason for my more round-about approach.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2006 07:34 AM
01-13-2006 07:34 AM
Re: Yet Another FTP Script
Does this script not contain a logic error? The time stamp on the remote file will change to the time at which it was downloaded, thus always being newer than the local file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2006 09:08 AM
01-13-2006 09:08 AM
Re: Yet Another FTP Script
In response to the suggestion to use 'newer', you wrote, "Does this script not contain a logic error? The time stamp on the remote file will change to the time at which it was downloaded, thus always being newer than the local file.".
This was exactly the reason I suggested my approach using 'modtime'.
You simply need to (1) open an ftp session to fetch the timestamp of the *remote* file that you *potentially* overwrite; (2) parse the returned timestamp string into a form suitable for creating a reference file with 'touch'; and (3) if the age relationship between the remote file (as know via the reference file) and the local file is suitable, then; (4) open a second ftp session to actually 'put' the file.
To fetch the timestamp information for parsing) simply collect it like this:
{ echo "open remotehost
user $user $passwd
modtime /path_to_remotefile
close"
} | ftp -i -n -v > /tmp/ftpresults
The file /tmp/ftpresults will contain the information you need to parse in step-2.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2006 05:31 AM
01-14-2006 05:31 AM
Re: Yet Another FTP Script
I have the sense that what I have suggested thus far may not have been clear. Hence, here's the "preamble" to deduce whether or not your local file is newer than the remote version you want to potentially replace. In the spirt of Unix, this is but one way to accomplish your goal:
#!/usr/bin/sh
#@(#) Query age of remote file before ftp - JRF
typeset myfile=${1} #...file being handled...
typeset host=hhhhhhhh #...SPECIFY !
typeset user=uuuuuuuu #...SPECIFY !
typeset pass=pppppppp #...SPECIFY !
typeset ftpdata=/tmp/ftpdata.$$
typeset reffile=/tmp/reffile.$$
trap 'rm -f ${ftpdata} ${reffile}" > /dev/null 2>&1' EXIT
{ echo "open ${host}
user ${user} ${pass}
modtime ${myfile}
close"
} | ftp -i -n -v > ${ftpdata}
ts=`perl -wlne 'print "$3$1$2$4$5.$6"
if (m%\s+(\d+).(\d+).(\d+)\s+(\d+).(\d+).(\d+)\s+%)' ${ftpdata}`
[ -z "${ts}" ] && { echo "Can't query ${myfile}"; exit 1; }
TZ=GMT touch -amt ${ts} ${reffile} #...ftp modtime returns in GMT,,,
if [ ! -f "${myfile}" ];then
echo "no local version of ${myfile} exists"
elif [ "${myfile}" -nt "${reffile}" ]; then
echo "local version is NEWER than remote version"
else
echo "local version is OLDER than remote version"
fi
echo "...now do what you wish to FTP..."
exit 0
Regards!
...JRF...