Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-07-20
8
Medium Priority
?
690 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 2000 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
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

Technology Partners: 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!

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

715 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