Solved

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

Posted on 2006-07-20
8
679 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

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 …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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