FTP scripting - Automate download of files and move files to an archive directory

One of my clients has a connection to an Unix environment where he starts some applications wich he uses in a Windows environment.

There is also a directory wich we can access by use a NFSclient, but after 2 days we have to reboot the server, to get the connection up and running again.

There is an other option, wich is downloading the files to a local directory by using FTP.

Now i am looking for a way to download the files and i have the following:

open <IP-address>
<username>
<password>
cd ..
cd ..
cd ..
cd ..
cd ..
cd var
cd appl
cd <application name>
prompt
lcd N:\<localdirectory>
mget *.aaa
mget *.AAA
mget *.bbb
mget *.BBB
bye

Open in new window


This works when i run it, but the files are still on the remote FTP location.

What i would like to do is putting these files in the Remote FTP directory ARCHIVE for an example.

I have found a sample code on a unix / linux form
#!/bin/sh
clear
# change local directory
cd [local-directory]

#collect file names
ftp -ni ftp.abccompany.com <<EOF
user [user] [password]
cd /OUT
mls W945*.* list.txt 
quit
EOF

# create ftp action list
echo >>todo.lst user [user] [password]
while read N
do
    echo >>todo.lst cd /OUT
    echo >>todo.lst get $N
    echo >>todo.lst rename $N ARCHIVE/$N
done <list.txt

echo >>todo.lst quit

# ftp transfer process
ftp -nv ftp.abccompany.com <todo.lst

# cleanup
rm todo.lst

Open in new window


But these commands doesn't work.

Can someone help me to get this working?
RemcoViCEOAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SandyCommented:
Please use pure-ftp having upload and run after scripts.
0
carlmdCommented:
The following script works... use it all the time.

#!/bin/ksh
#
    HOST='remotehostname'
    USERN='anonymous'
    PASS='mm'
    cd /usr/sys/inst.images/update
    echo `ftp -inv ${HOST} >/home/ftp.como <<EndFTP
    user "${USERN}" "${PASS}"
    cd /remote/path
    binary
    mget *
    quit
    EndFTP`

NOTE that the marks before the "ftp" and after"EndFTP" are back tics. You MUST use these. I suggest you cut and past this script into vi or other editor on unix and edit it there.

remotehostname -> the path/url to the remote site you want to get files from
USERN=  -> the login name you use at the remote site
PASS=  -> the password you use at the remote site
cd /usr/....  -> this is a "cd" on you local system to where you want to put the downloaded files
echo   -> this creates a file in the path /home/ftp.como (change as you wish) that contains all that goes by in the download,
                  this is valuable if you have any problems or just want to see what happens
user   -> this logs you in on the remote system (don't change this)
cd /remote/path  -> change this to be the path on the remote site where you want to get the files from
binary -> this indicates the download is a binary file, if files are ascii you can omit this line, but it does not hurt anyway
mget * -> get all the files in the directory you cd'ed to. If you wanted all files that started with "text" then make this mget text*

Save this script with your changes and make sure it is executable. (chmod a+x script).

You can run this script without using a terminal session by using the "at" command
For example:
        at now today /path/myscript             will run the script in the background now
        at 8 pm today /path/myscript           will run the script at 8PM today
for other option see man pages for at
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MikeOM_DBACommented:
To get the files and then move them to another directory, try this:
#!/bin/ksh
#
SRCHOST=remoteHost
USER=MySelf
PASS=WhoCares
SRCDIR=/remote/file/dir
ARCDIR=/remote/file/archive
TGTDIR=/local/file/path

cd $TGTDIR

#get list of file names to transfer
ftpcmd=`
ftp -ni $SRCHOST <<EOF | grep -v ^ftp | xargs -i? echo "get "?"\nrename "?" $ARCDIR/"?
user $USER pass $PASS
cd $SRCDIR
ls -1  *.aaa
ls -1  *.AAA
ls -1  *.bbb
ls -1  *.BBB
bye
EOF`

# Execute the file transfer
ftp -ni $SRCHOST <<EOF
user $USER pass $PASS
cd $SRCDIR
$ftpcmd
bye
EOF

Open in new window

:p
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

RemcoViCEOAuthor Commented:
Problem is that these scripts are for running on a unix environment, but i am connecting to a Unix environment, not running one.

I need to start the command on a Windows 2008 server, wich then connects to the ftp running on a Unix environment.

I tried the above anyway, but i can't get it to work.
0
carlmdCommented:
Sorry, the fact that you wanted to run this from Windows was not clear.

Take a look at:

http://support.microsoft.com/kb/96269

and

http://support.microsoft.com/kb/555976

and

http://www.howtogeek.com/howto/windows/how-to-automate-ftp-uploads-from-the-windows-command-line/

one of these should answer your question
0
RemcoViCEOAuthor Commented:
I just bought a software license for a specific product wich makes scripting easier on FTP and it also has the option to do the things i want.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.