Solved

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

Posted on 2006-07-20
8
689 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 17169785
cd /data/dev/data/receive/
0
 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

636 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