Discussion Locked

Chang filename on remote Computer / FTP

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
We receive various files from clients through our Sun box running Solaris 7. They will either dial-in or use ftp. This is only a staging area, we then need to send these files to our HP3000 for processing. Our analysts would like to have these files named according to the current date, for example, ABC0131 the next one would be ABC0201. I'm doing this manually now, but would like to create a script that automatically changes the name during the ftp process. I wrote a script that will change the name on the Solaris box but I am stumped when it comes to using ftp to send them to the HP3000. In my script, I pick up the file with the modified name, and want to use that modified name on the remote, but I don't know of a way to do that dynamcially. Is there a way to send these files over to a remote location, with ftp, that will automatically take into account file names that change names on a daily basis? Thanks

4 replies

by stillatit

Take your script to the point where you have the current name of the the file and the new name you want the file to be. Shove those names in two variables:

MYCURRENTNAME=currentname
MYNEWNAME=giveitthisname

(whatever they are). Now write a tempory file in a secure directory to which only you have read access:

MYTEMPFILE='/home/username/mysecure/mytemp'
# variable for the secure location and file name
HPADDR="1.2.3.4"
# variable for the IP address of the HP box - put in the right address
#
MYUSER="username"
# replace 'usernamne' with your user name on the HP
MYPASS="mypassword"
# replace 'mypassword' with your password on the HP
#
#
echo "open $HPADDR" > $MYTEMPFILE
# connect to the HP
echo "user $MYUSER $MYPASS" >>$MYTEMPFILE
# log in
echo "bin" >> $MYTEMPFILE
# force binary
#
echo "put $MYCURRENTNAME $MYNEWNAME" >> $MYTEMPFILE
# having the two names causes a rename in transit.
echo "bye" >> $MYTEMPFILE
# now execute ftp and execute the commands.
# The -n inhibits automatic login.
/usr/bin/ftp -n <$MYTEMPFILE
# and kill off the temp file
/usr/bin/rm $MYTEMPFILE
#At this point you may want to move the file to a "sent" folder in case the HP loses it.
NEWLOC="../sent"
# Put in the path where you want the sent files to go
/bin/mv $MYCURRENTNAME $NEWLOC/$MYNEWNAME
# or kill it, or whatever

Alternately you could have the first three lines (open, user, bin) in a file in your secure directory, and copy that into the new temp file name, then append the rest of the lines. That puts the password only in your unreadable directory rather than in a script.

Good luck.

This discussion is closed to new replies.