Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Unix Operating Systems > Sco Unix

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-24-2008, 04:43 PM
Julian Brett
 
Posts: n/a
Default Scripted FTP transfer

Hi all.

I'm attempting to script an FTP transfer on my UnixWare 7.1.4 server. I've
written numerous FTP transfer scripts before, but haven't really approached
it this way.

What I'd like to do is basically retrieve some files from a remote system,
then move them at the remote end into an archive folder. Sounds pretty
simple.

In my script, I'm trying to write a FTP command file on the fly to redirect
into my FTP command as follows:-

===========
:
ftphost=ftp.XXXXXX.com
ftpuser=XXXXXX
ftppass=XXXXXX
ftpdir="/"
ftparcdir="/arcdir"
work=/tmp/xfer.$$
#
# get list of files waiting
ftp -g -n ${ftphost} > ${work} 2>&1 << !
user ${ftpuser} ${ftppass}
cd ${ftpdir}
dir
bye
!

# process file list into ftp commands
exec 3< ${work}
while read line <&3
do
filename=`echo ${line} | awk '{print $4}'`
fileext=`echo ${filename} | awk -F\. '{print $2}' | dd conv=ucase
2>/dev/null`
if [ "${fileext}" = "XML" ]
then
echo "get ${filename}" >> ${work}.2
echo "ren ${filename} ${ftparcdir}/${filename}" >> ${work}.3
fi
done

# write ftp script file to retrieve all XML files
#echo "OPEN ${ftphost}" > /tmp/ftp.$$
echo "USER ${ftpuser} ${ftppass}" >> /tmp/ftp.$$
echo "binary" >> /tmp/ftp.$$
echo "cd ${ftpdir}" >> /tmp/ftp.$$
cat ${work}.2 >> /tmp/ftp.$$
cat ${work}.3 >> /tmp/ftp.$$
echo "bye" >> /tmp/ftp.$$

# run script to transfer all XML files and archive them
ftp -i -g -n ${ftphost} < /tmp/ftp.$$ > /tmp/ftp$$.log 2>&1
rm -f ${work} ${work}.2 ${work}.3

cat /tmp/ftp$$.log
rm -f /tmp/ftp$$.log
rm -f /tmp/ftp.$$

exit 0

===========

The script runs and creates my command file, but I just cannot get it to
accept the commands from the temporary file. I have removed the redirect to
the ftp$$.log file, and stripped out the relevant commands and run them
directly from the command line.

The output I get (either on the screen, or in the ftp$$.log file) is:-

?Invalid command
?Invalid command
Not connected.
Not connected.
Not connected.
Not connected.
Not connected.
Not connected.


This is the method for ftp which I have found on Google, but cannot
understand why it isn't working on my Unixware system. I get exactly the
same results on an Openserver 5.0.6 system too.

Any ideas what I'm doing wrong here?


I suppose I could also do a "mget *.xml" in this instance, but not knowing
the case of the files (it could be another Unix or Linux system at the other
end - I don't know), this may not work.



Many thanks,

Julian.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-24-2008, 04:43 PM
Nico Kadel-Garcia
 
Posts: n/a
Default Re: Scripted FTP transfer

ThreeStar wrote:

> Sounds like a problem with the command file (/tmp/ftp.$$). Post
> that. From the "Not connected" errors I'm guessing it's a problem
> with establishing user credentials. Are you able to FTP interactively
> to the host from this box?
>
> BTW if this script is designed to run in a particular context I'd
> use .netrc files to contain the user name and password instead of
> echoing them in the script. It's somewhat more secure, makes the
> password easier to change, and simplifies your script.
>
> Better yet is SCP, but you didn't ask about that.
>
> R Robert
> *** Software


SCP is *AWFUL* for this sort of thing. It mishandles symlinks, and SCP or SFTP
access provides user access to the rest of the server's file system, with the
user's normal privileges. That presents a real security issue.

I'm a big proponent of WebDAV over HTTPS fur just this sort of thing, and for
rsync over SSH with a restricted validation script as needed.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-24-2008, 04:43 PM
Bill Campbell
 
Posts: n/a
Default Re: Scripted FTP transfer

On Tue, Apr 22, 2008, Nico Kadel-Garcia wrote:
>ThreeStar wrote:
>
>> Sounds like a problem with the command file (/tmp/ftp.$$). Post
>> that. From the "Not connected" errors I'm guessing it's a problem
>> with establishing user credentials. Are you able to FTP interactively
>> to the host from this box?
>>
>> BTW if this script is designed to run in a particular context I'd
>> use .netrc files to contain the user name and password instead of
>> echoing them in the script. It's somewhat more secure, makes the
>> password easier to change, and simplifies your script.
>>
>> Better yet is SCP, but you didn't ask about that.
>>
>> R Robert
>> *** Software

>
>SCP is *AWFUL* for this sort of thing. It mishandles symlinks, and SCP or SFTP
>access provides user access to the rest of the server's file system, with the
>user's normal privileges. That presents a real security issue.
>
>I'm a big proponent of WebDAV over HTTPS fur just this sort of thing, and for
>rsync over SSH with a restricted validation script as needed.


Depending on the nature of the data, we often use rsync's modules
to handle things like this, restricting access by IP address.
Doing it that way does not require things like ssh identities with
empty pass phrases or other potential security issues.

Bill
--
INTERNET: bill@celestial.com Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
Voice: (206) 236-1676 Mercer Island, WA 98040-0820
Fax: (206) 232-9186

Each individual of the society has a right to be protected in the
enjoyment of his life, liberty, and property no part of the property
of any individual can, with justice, be taken from him, or applied to
public uses, without his own consent -- John Adams
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-24-2008, 04:43 PM
ThreeStar
 
Posts: n/a
Default Re: Scripted FTP transfer

On Apr 22, 2:34 am, "Julian Brett" <nos...@nospamhere.com> wrote:
> Hi all.
>
> I'm attempting to script an FTP transfer on my UnixWare 7.1.4 server. I've
> written numerous FTP transfer scripts before, but haven't really approached
> it this way.
>
> What I'd like to do is basically retrieve some files from a remote system,
> then move them at the remote end into an archive folder. Sounds pretty
> simple.
>
> In my script, I'm trying to write a FTP command file on the fly to redirect
> into my FTP command as follows:-
>
> ===========
> :
> ftphost=ftp.XXXXXX.com
> ftpuser=XXXXXX
> ftppass=XXXXXX
> ftpdir="/"
> ftparcdir="/arcdir"
> work=/tmp/xfer.$$
> #
> # get list of files waiting
> ftp -g -n ${ftphost} > ${work} 2>&1 << !
> user ${ftpuser} ${ftppass}
> cd ${ftpdir}
> dir
> bye
> !
>
> # process file list into ftp commands
> exec 3< ${work}
> while read line <&3
> do
> filename=`echo ${line} | awk '{print $4}'`
> fileext=`echo ${filename} | awk -F\. '{print $2}' | dd conv=ucase
> 2>/dev/null`
> if [ "${fileext}" = "XML" ]
> then
> echo "get ${filename}" >> ${work}.2
> echo "ren ${filename} ${ftparcdir}/${filename}" >> ${work}.3
> fi
> done
>
> # write ftp script file to retrieve all XML files
> #echo "OPEN ${ftphost}" > /tmp/ftp.$$
> echo "USER ${ftpuser} ${ftppass}" >> /tmp/ftp.$$
> echo "binary" >> /tmp/ftp.$$
> echo "cd ${ftpdir}" >> /tmp/ftp.$$
> cat ${work}.2 >> /tmp/ftp.$$
> cat ${work}.3 >> /tmp/ftp.$$
> echo "bye" >> /tmp/ftp.$$
>
> # run script to transfer all XML files and archive them
> ftp -i -g -n ${ftphost} < /tmp/ftp.$$ > /tmp/ftp$$.log 2>&1
> rm -f ${work} ${work}.2 ${work}.3
>
> cat /tmp/ftp$$.log
> rm -f /tmp/ftp$$.log
> rm -f /tmp/ftp.$$
>
> exit 0
>
> ===========
>
> The script runs and creates my command file, but I just cannot get it to
> accept the commands from the temporary file. I have removed the redirect to
> the ftp$$.log file, and stripped out the relevant commands and run them
> directly from the command line.
>
> The output I get (either on the screen, or in the ftp$$.log file) is:-
>
> ?Invalid command
> ?Invalid command
> Not connected.
> Not connected.
> Not connected.
> Not connected.
> Not connected.
> Not connected.
>
> This is the method for ftp which I have found on Google, but cannot
> understand why it isn't working on my Unixware system. I get exactly the
> same results on an Openserver 5.0.6 system too.
>
> Any ideas what I'm doing wrong here?
>
> I suppose I could also do a "mget *.xml" in this instance, but not knowing
> the case of the files (it could be another Unix or Linux system at the other
> end - I don't know), this may not work.
>
> Many thanks,
>
> Julian.


Sounds like a problem with the command file (/tmp/ftp.$$). Post
that. From the "Not connected" errors I'm guessing it's a problem
with establishing user credentials. Are you able to FTP interactively
to the host from this box?

BTW if this script is designed to run in a particular context I'd
use .netrc files to contain the user name and password instead of
echoing them in the script. It's somewhat more secure, makes the
password easier to change, and simplifies your script.

Better yet is SCP, but you didn't ask about that.

R Robert
*** Software
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-24-2008, 04:43 PM
David Font
 
Posts: n/a
Default Re: Scripted FTP transfer

Rather then specify the username and password in your script, I would
suggest you put the ftp destination name/IP address, user name and password
details in to a .netrc file in the home directory of the user name that is
going to run the ftp script, so....

If you are running this from root, the .netrc will be created in /

The format of .netrc would be:

machine name/IP address login username password password

set chmod to 600 for .netrc. Then run your script minus the ftpuser and
ftppass variables

Dave

"Julian Brett" <nospam@nospamhere.com> wrote in message
news:fukbc8$mej$1$8300dec7@news.demon.co.uk...
> Hi all.
>
> I'm attempting to script an FTP transfer on my UnixWare 7.1.4 server.
> I've written numerous FTP transfer scripts before, but haven't really
> approached it this way.
>
> What I'd like to do is basically retrieve some files from a remote system,
> then move them at the remote end into an archive folder. Sounds pretty
> simple.
>
> In my script, I'm trying to write a FTP command file on the fly to
> redirect into my FTP command as follows:-
>
> ===========
> :
> ftphost=ftp.XXXXXX.com
> ftpuser=XXXXXX
> ftppass=XXXXXX
> ftpdir="/"
> ftparcdir="/arcdir"
> work=/tmp/xfer.$$
> #
> # get list of files waiting
> ftp -g -n ${ftphost} > ${work} 2>&1 << !
> user ${ftpuser} ${ftppass}
> cd ${ftpdir}
> dir
> bye
> !
>
> # process file list into ftp commands
> exec 3< ${work}
> while read line <&3
> do
> filename=`echo ${line} | awk '{print $4}'`
> fileext=`echo ${filename} | awk -F\. '{print $2}' | dd conv=ucase
> 2>/dev/null`
> if [ "${fileext}" = "XML" ]
> then
> echo "get ${filename}" >> ${work}.2
> echo "ren ${filename} ${ftparcdir}/${filename}" >> ${work}.3
> fi
> done
>
> # write ftp script file to retrieve all XML files
> #echo "OPEN ${ftphost}" > /tmp/ftp.$$
> echo "USER ${ftpuser} ${ftppass}" >> /tmp/ftp.$$
> echo "binary" >> /tmp/ftp.$$
> echo "cd ${ftpdir}" >> /tmp/ftp.$$
> cat ${work}.2 >> /tmp/ftp.$$
> cat ${work}.3 >> /tmp/ftp.$$
> echo "bye" >> /tmp/ftp.$$
>
> # run script to transfer all XML files and archive them
> ftp -i -g -n ${ftphost} < /tmp/ftp.$$ > /tmp/ftp$$.log 2>&1
> rm -f ${work} ${work}.2 ${work}.3
>
> cat /tmp/ftp$$.log
> rm -f /tmp/ftp$$.log
> rm -f /tmp/ftp.$$
>
> exit 0
>
> ===========
>
> The script runs and creates my command file, but I just cannot get it to
> accept the commands from the temporary file. I have removed the redirect
> to the ftp$$.log file, and stripped out the relevant commands and run them
> directly from the command line.
>
> The output I get (either on the screen, or in the ftp$$.log file) is:-
>
> ?Invalid command
> ?Invalid command
> Not connected.
> Not connected.
> Not connected.
> Not connected.
> Not connected.
> Not connected.
>
>
> This is the method for ftp which I have found on Google, but cannot
> understand why it isn't working on my Unixware system. I get exactly the
> same results on an Openserver 5.0.6 system too.
>
> Any ideas what I'm doing wrong here?
>
>
> I suppose I could also do a "mget *.xml" in this instance, but not knowing
> the case of the files (it could be another Unix or Linux system at the
> other end - I don't know), this may not work.
>
>
>
> Many thanks,
>
> Julian.
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-24-2008, 04:43 PM
Tony Lawrence
 
Posts: n/a
Default Re: Scripted FTP transfer

On Apr 22, 5:34 am, "Julian Brett" <nos...@nospamhere.com> wrote:
> Hi all.
>
> I'm attempting to script an FTP transfer on my UnixWare 7.1.4 server. I've
> written numerous FTP transfer scripts before, but haven't really approached
> it this way.



Don't do this. There are better ways to transfer files. If it must
be ftp, use Perl:
http://aplawrence.com/Unixart/perlnetftp.html

Much easier, much more control, much more reliable.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-24-2008, 04:43 PM
ThreeStar
 
Posts: n/a
Default Re: Scripted FTP transfer

On Apr 22, 8:06 am, Nico Kadel-Garcia <nka...@gmail.com> wrote:
> ThreeStar wrote:
> > Sounds like a problem with the command file (/tmp/ftp.$$). Post
> > that. From the "Not connected" errors I'm guessing it's a problem
> > with establishing user credentials. Are you able to FTP interactively
> > to the host from this box?

>
> > BTW if this script is designed to run in a particular context I'd
> > use .netrc files to contain the user name and password instead of
> > echoing them in the script. It's somewhat more secure, makes the
> > password easier to change, and simplifies your script.

>
> > Better yet is SCP, but you didn't ask about that.

>
> > R Robert
> > *** Software

>
> SCP is *AWFUL* for this sort of thing. It mishandles symlinks, and SCP or SFTP
> access provides user access to the rest of the server's file system, with the
> user's normal privileges. That presents a real security issue.
>
> I'm a big proponent of WebDAV over HTTPS fur just this sort of thing, and for
> rsync over SSH with a restricted validation script as needed.


AFAIK the only issue is that SCP copies symbolic links as files, which
isn't necessarily a bad thing.

I assume one would use SCP keys only for a user with restricted
permissions. So it doesn't necessarily follow that SCP exposes the
whole server.

Better security is better, even if it's not the best security
(whatever that means). SCP fits the simple scenario the poster laid
out, and avoids sending login credentials over the Internet in clear
text like FTP does. WebDAV and the other proposed solutions may be
better yet, although we don't know enough about the poster's equipment
or requirements or abilities to say for sure.

--RLR
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-24-2008, 04:43 PM
Joe Dunning
 
Posts: n/a
Default Re: Scripted FTP transfer



On Tue, 22 Apr 2008, ThreeStar wrote:

>
> Better security is better, even if it's not the best security
> (whatever that means). SCP fits the simple scenario the poster laid
> out, and avoids sending login credentials over the Internet in clear
> text like FTP does.


There are FTP implementations available that support encryption. They
won't work through many firewalls, but as long as only one end has an
external firewall, they can be used.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-24-2008, 04:43 PM
Bob Rasmussen
 
Posts: n/a
Default Re: Scripted FTP transfer

On Tue, 22 Apr 2008, Joe Dunning wrote:

> There are FTP implementations available that support encryption. They
> won't work through many firewalls, but as long as only one end has an
> external firewall, they can be used.


Are you referring to FTP over SSL, sometimes known as FTPS? If not, what?

Regards,
.....Bob Rasmussen, President, Rasmussen Software, Inc.

personal e-mail: ras@anzio.com
company e-mail: rsi@anzio.com
voice: (US) 503-624-0360 (9:00-6:00 Pacific Time)
fax: (US) 503-624-0760
web: http://www.anzio.com
street address: Rasmussen Software, Inc.
10240 SW Nimbus, Suite L9
Portland, OR 97223 USA
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-24-2008, 04:43 PM
bcohen@example.com
 
Posts: n/a
Default Re: Scripted FTP transfer

In article <fukbc8$mej$1$8300dec7@news.demon.co.uk>, Julian Brett wrote:
> Hi all.
>
> I'm attempting to script an FTP transfer on my UnixWare 7.1.4 server. I've
> written numerous FTP transfer scripts before, but haven't really approached
> it this way.




This sort of thing in a script file has always worked for me
under various unixen:



cd_dir="somedir"
file="somefile.txt"
user="myusername"
host="myhost.com"
echo -n "Password for ${user} at ${host}: "
read pass

echo "
open ${host}
user ${user} ${pass}
#passive
bin
hash
prompt
cd ${cd_dir}
pwd
ls
chmod 700 *
mdele *
put ${file}
chmod 000 *
ls
" | ftp -n

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 02:59 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62