0

From my linux machine, I connect remotely to an FTP server using the following command:

ftp ftp://USERNAME:PASSWORD@FTPSERVER/array1/DIR1/DIR2/

In this DIR2 there is a file called running_config which is routinely deposited there,automatically, once a day.

I would like to append the value of date into the name of this file. How can I can achieve this?

  • How exactly do you need this to happen? Why not use cron to take care of this? I'm pretty sure logrotate should be able to do this too. If not, you can always make a cron script that runs daily at a specific time, moves/copies your files and appends $(date +%Y-%m-%d) to its name. – confetti Sep 14 '18 at 20:40
  • I don't know how to write such complicated script. – hoanggeneral Sep 14 '18 at 21:07
1

According to man ftp:

The append and put subcommands perform file-name expansion and then use only the first file name generated. Other ftp subcommands, such as cd, delete, get, mkdir, rename, and rmdir, do not perform file-name expansion and take the pattern-matching characters literally.

You could try something like:

ftp> put running_config running_config_021345

If you would like to append date, then you need to capture date as follows:

ftp> put running_config running_config_`date +%Y%m%d`.txt

Here is an example of a bash:

#!/bin/bash
HOST_name='your_ftp_site'
USER='remote_user_name'
PW='remote_password'

ftp -n -v $HOST_name << EOT
ascii
user $USER $PW
prompt
 put running_config running_config_`date +%d-%m-%Y`.txt

EOT
  • 1
    how can I capture date as a variable and code the process in this case? – hoanggeneral Sep 14 '18 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.