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
Solved

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

Posted on 2006-07-20
8
682 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

789 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