jumprooster
asked on
ftp unix shell .sh upload file based on first part of file name
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
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:
aaa_aaa_901_20060720_14:46
aaa_aaa_902_20060720_14:46
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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?
cd /data/dev/data/receive/
ASKER
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
so I want to change the default directory on the target server to directly upload these files to
cd is a ftp command too
You can either do
mput $FILE /data/dev/data/receive
or
cd /data/dev/data/receive
mput $FILE
mput $FILE /data/dev/data/receive
or
cd /data/dev/data/receive
mput $FILE
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
mput aa_aaa_*