Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

Automate FTP

Hello champs,

I am trying to write a routine that automates FTP transfers. I was using ftpput in Busybox but it consumes way too much memory. I've seen some examples but they are in ksh and Perl? I am sort of a newbie in linux, I know how some things work but have still got a lot to learn.

I paste the example I found from a linux forum.

Example from here (http://www.unix.com/answers-frequently-asked-questions/14020-automate-ftp-scripting-ftp-transfers.html):

#! /usr/bin/ksh

host=remote.host.name

user=whoever

passwd=whatever

exec 4>&1

ftp -nv >&4 2>&4 |&

print -p open $host

print -p user $user $passwd

print -p cd directory

print -p binary

print -p put tar.gz

print -p bye

wait

exit 0

However, I don't know if there is a 'print' command in msh or sash

I think this would be a lighter option over SSH.

Any ideas will be appreciated.

Thanks in advance.

14 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I don't understand the "EOF" that is piped. maybe this foirst must be declared somehow to be used with the actual shell that can't be bash in a NIOS device.

    If you use the sahs shell as default, yopu need to activate hush in buisibox and add a line

    # !/bin/hush

    at the beginning of the script, as sash can't do piping.

    -Michael
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    <div class='quotetop'>QUOTE (mschnell @ Jul 15 2009, 05:00 AM) <{post_snapback}> (index.php?act=findpost&pid=23128)</div>

    --- Quote Start ---

    I don&#39;t understand the "EOF" that is piped. maybe this foirst must be declared somehow to be used with the actual shell that can&#39;t be bash in a NIOS device.[/b]

    --- Quote End ---

    Michael, I don&#39;t understand it 100% either, but in my understanding the <<EOF is what splits the script into two parts: the first (before <<EOF) goes to your default shell (bash, in my Ubuntu) and the second part is used as input commands for the ftp client that is started. So, after the EOF, it is the same as you started ftp manually and typed the lines one by one - but that wouldn&#39;t be automated, of course.

    <div class='quotetop'>QUOTE (mschnell @ Jul 15 2009, 05:00 AM) <{post_snapback}> (index.php?act=findpost&pid=23128)</div>

    --- Quote Start ---

    If you use the sahs shell as default, yopu need to activate hush in buisibox and add a line[/b]

    --- Quote End ---

    The script is run in my desktop PC/Ubuntu machine, so it has nothing to do with the uClinux shell. In my Nios box, I use sash as the default shell.

    Cheers,

    Ricardo.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    This is something I wrote to the forum before it crashed that I found on google that may be of help.

    "I found a few things on the internet and adapted them today to make life easier. Try this shell script.

    # !/bin/sh

    {

    echo "open uClinux"

    echo "user root uClinux"

    echo "put ./test /bin/test"

    echo "bye"

    } | ftp -vin

    {

    echo "open uClinux"

    sleep 1

    echo "root"

    sleep .2

    echo "uClinux"

    sleep .5

    echo "chmod 777 /bin/test"

    sleep .5

    echo "gdbserver localhost:10000 /bin/test"

    sleep 1

    } | telnet

    # end of file#

    "

    This is just an alternate way, but if it helps anyone........
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    <div class='quotetop'>QUOTE (Nails @ Jul 21 2009, 08:12 PM) <{post_snapback}> (index.php?act=findpost&pid=23236)</div>

    --- Quote Start ---

    #!/bin/sh

    {

    echo "open uClinux"

    echo "user root uClinux"

    echo "put ./test /bin/test"

    echo "bye"

    } | ftp -vin[/b]

    --- Quote End ---

    With this, "sh" needs to be hush (or msh), as sash, which had been the default shell "/bin/sh" for quite a time, does not support piping ("|").

    The very new version of uClinux dist (provided on the blackfin server) does use hush as default shell, though.

    But you can actiate hush (e.g. in busybox) additionally to sash, and start the script with# !/bin/sash.

    -Michael