Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 507
  • Last Modified:

Move files from WamNet to server using ftp

Hello all,

I am a complete beginner at writing scripts and have been given a project to get me started.

I have been asked to write a script that will move .zip files from our WamNet! server (linux) to our server (Solaris 9) to keep as and when needed.

The files should be moved automatically as they finish uploading to the WamNet! server.

Once moved, the files are to be unzipped using the code the client has supplied:

echo `date` >> ~/Desktop/Economist_unzipped_log
for i in `ls *.zip`;
do
echo $i >> ~/Desktop/Economist_unzipped_log
unzip -uo $i
done
echo `date` >> ~/Desktop/Economist_unzipped_log

I'm sure I've left out some vital information. Please let me know whatever you need to know in order to make this work.

Thank you in advance,

Anthony
0
stuffedparrot
Asked:
stuffedparrot
  • 5
  • 3
2 Solutions
 
TintinCommented:
Firstly, let's clean up the supplied client code (which is obviously written by someone without scripting experience)

LOG=~/Desktop/Economist_unzipped_log
date >>$LOG

for file in *.zip
do
  echo $file >>$LOG
  unzip -uo $file
done

date >>$LOG


A few questions you need to answer are:

1.  Do you control the process on the Linux side, ie: the creation of the zip files?
2.  What access do you have to the Linux server?  ssh, ftp?
0
 
stuffedparrotAuthor Commented:
Good morning,

To answer your questions:

1. We do not have any say as to how the .zip files are created or the frequency in which they're added to the WamNet! linux box.

2. We have both ssh and ftp.

Thank you for your swift reply.

Anthony
0
 
TintinCommented:
If you don't have any control of the zip file creation, then it can be tricky to know when the zip file has been finished writing to.

Are these zip files created many times a day?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
stuffedparrotAuthor Commented:
The .zip files are made at the Economists offices and ftp'd to our Wamnet box as a complete .zip file about ten times a day.

Thank you.
0
 
stuffedparrotAuthor Commented:
Any ideas anyone?

Thank you.
0
 
TintinCommented:
Sorry, got delayed.

Using scp is your best option if you setup ssh keys.  The script would then look like:

#!/bin/sh
LOG=~/Desktop/Economist_unzipped_log

cd ~/Desktop # or whereever you want the zip files
scp user@remote-server:*.zip .

date >>$LOG

for file in *.zip
do
  echo $file >>$LOG
  unzip -uo $file
done

date >>$LOG


The FTP version would look like:

#!/bin/sh
LOG=~/Desktop/Economist_unzipped_log

cd ~/Desktop # or whereever you want the zip files

ftp -inv <<EOF
  open remote-server
  user username password
  prompt
  mget *.zip
  quit
EOF

date >>$LOG

for file in *.zip
do
  echo $file >>$LOG
  unzip -uo $file
done

date >>$LOG


0
 
stuffedparrotAuthor Commented:
Thank you Tintin.

I shall give your suggestions a go during the day today (Friday).

Enjoy your weekend.

Anthony
0
 
stuffedparrotAuthor Commented:
Sorry,

I have been preoccupied with something else and luckily I was given some time to sort the above problem out.

I shall hopefully be returning to finding a solution later this week so will be back for more suggestions soon.

Thank you,

Tony
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now