If I wanted a machine to put a specific file onto another OS far across the internet via FTP - and I wanted to do it automatically not user intervented, how would I do that?
Use the PUT command?
The file name and position never changes, it gets overwritten and the system on the other end takes care of all the dirty work. I just need the unix server to FTP that one file.
I keep getting these requests, driven me nuts.
Now I need to be able to put a variable. Variables do not get handed off well to the FTP process commands.
Any ideas?
Example: I wanna put this command in place
put $1.backup.file
FTP is not pulling the filename correctly - I get cannot find file $1.backup.file
We use variations on the following script all over the place. We designed an "FTP server" written in korn shell to handle ALL FTP's between different platforms aw well as our corporate "Enterprise FTP server (Sterling Mailbox)
All variables are defined before invoking the FTP. (Currently in a flat file - soon to be in a DB table)
Contents of DYNAM_FTP.KSH:
#!/etc/usr/ksh
assorted variable assignments
ftp -n -v $HOSTNAME <<-END
user $USERID $PASSWORD
cd $SRC_DIR
lcd $TARGET_DIR
pwd
get $SRC_FILE
END
The above "here document" is dynamically built based on a control record which specifies source info (IP, id, password, filename, etc.)
External to the above:
chmod +x DYNAM_FTP.KSH
DYNAM_FTP.KSH to invoke
We capture the output of the above to a file and then grep for various errors....
[Edited by kornshellmaven on 05-12-2001 at 06:58 PM]
Not sure why it's not expanding the variables within the here-document - Turn xtrace on to see commands echoed back
The following works fine
#!/usr/bin/ksh -x
DATA=$AL_DATA
ftp -n -v slapdev <<-END
user userid password
pwd
cd $DATA
pwd
END
It doesn't matter if I cd to $DATA or $AL_DATA (exported variable)- it gets expanded OK
We also have routines to build the FTP here-doc dynamically
exec 4>dynam_ftp.sh
print -u4 "#!/usr/bin/ksh -x"
print -u4 "ftp -v -n $DEST <<-END"
print -u4 "user $USER $PASSWORD"
print -u4 "cd $DATA"
print -u4 "pwd"
print -u4 "lcd $SRC_DIR"
print -u4 "mget $FILE_PATTERN"
print -u4 "END"
chmod +x dynam_ftp.sh
dynam_ftp.sh
The contents of the dynam_ftp.sh file will have the fully expanded variable values. The above might be a little overkill for your needs.