Solved

ftp unix shell .sh upload file based on first part of file name

Posted on 2006-07-20
8
673 Views
Last Modified: 2013-12-26
Hi,

I have a .sh unix shell script. I want it to ftp files to the server. The filenames have the datatime stamped at the end of their names so that is always different but the first part of the filename is always the same.

So I want to upload these files to the server.

I have an ftp script, I just need to get the filenames part to work.

Here's the script so far:

#!/bin/sh
HOST='a2'
USER='u1'
PASSWD='p1'
FILE=<I need the code here>

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0

Here are some examples of the files I have:

aa_aaa_900_20060720_14:46:46.txt
aaa_aaa_901_20060720_14:46:51.txt
aaa_aaa_902_20060720_14:46:57.txt

I need the to upload all 3. So this would be putting all files with "aa_aaa_" at the beginning of the filename.

500 points A grade guaranteed





0
Comment
Question by:jumprooster
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 17150613
You can use mput for wild card expansion. The following command  will upload all your 3 files. ( from your example, not sure if you want aa_aaa or aaa_aaa)
mput aa_aaa_*
0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 17150878
Putting it all together

#!/bin/sh
HOST='a2'
USER='u1'
PASSWD='p1'
FILE='aa_aaa_*'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
prompt
mput $FILE
quit
END_SCRIPT
0
 

Author Comment

by:jumprooster
ID: 17169588
how would I upload it to a specific directory on that server ?
right now it gets uploaded directly to the default directory. how could I change that?

lets say that the current directory is /aa/home by default (on the host server which is a2

if I want to upload the files to a different directory let's say /data/dev/data/receive/ for example which is a different path

how could I do the ftp like that?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17169785
cd /data/dev/data/receive/
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:jumprooster
ID: 17170216
the problem is that the ftp script is running on a different server

so I want to change the default directory on the target server to directly upload these files to
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17170263
cd is a ftp command too
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17173038
You can either do

mput $FILE /data/dev/data/receive

or

cd /data/dev/data/receive
mput $FILE
0
 
LVL 6

Expert Comment

by:JJSmith
ID: 17188448

As previously informed - cd applies to the remote directory not the local.

although you are focusing on the 'cd' - don't overlook something tintin added to the solution.

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
prompt
mput $FILE
quit
END_SCRIPT

the 'prompt' is very important - without it your script will interactively ask for each file in the mput to be transfered.

prompt is a toggle setting - by default it is on.

Cheers
JJ
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now