Delete old files from FTP Storage


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete old files from FTP Storage
# 8  
Old 01-20-2015
Code:
whereis ftp
ftp: /usr/bin/ftp /usr/share/man/man1/ftp.1.gz
type -a ftp
ftp is /usr/bin/ftp

Then:
Code:
listing=`/usr/bin/ftp -i -n $ftpsite <<EOMYF

# 9  
Old 01-20-2015
Hello,
sorry for bad question but should it looks like:
Code:
#!/bin/bash
# get a list of files and dates from ftp and remove files older than ndays
ftpsite="HOST"
ftpuser="USER"
ftppass="PASSWORD"

# age of files they should delete
ndays=1


# work out our cutoff date
MM=`date --date="$ndays days ago" +%b`
DD=`date --date="$ndays days ago" +%d`


echo removing files older than $MM $DD

# get directory listing from remote source
whereis ftp
ftp: /usr/bin/ftp /PATH/TO/FOLDER/
type -a ftp
ftp is /usr/bin/ftp

listing=`/usr/bin/ftp -i -n $ftpsite <<EOMYF`
lista=( $listing )

# loop over our files
for ((FNO=0; FNO<${#lista[@]}; FNO+=9));do
  # month (element 5), day (element 6) and filename (element 8)
  #echo Date ${lista[`expr $FNO+5`]} ${lista[`expr $FNO+6`]}          File: ${lista[`expr $FNO+8`]}

  # check the date stamp
  if [ ${lista[`expr $FNO+5`]}=$MM ];
  then
    if [[ ${lista[`expr $FNO+6`]} -lt $DD ]];
    then
      # Remove this file
      echo "Removing ${lista[`expr $FNO+8`]}"
      ftp -i -n $ftpsite <<EOMYF2 
      user $ftpuser $ftppass
      binary
      cd $putdir
      delete ${lista[`expr $FNO+8`]}
      quit
EOMYF2


    fi
  fi
done

Or how it should looks like?
# 10  
Old 01-20-2015
No.
The whereis/type commands were used to show you WHAT the absolute path of ftp is (read the respective man page!). Use those interactively before/when editing the script.
In the script, replace ftp by your findings, in MY case /usr/bin/ftp. Do it for every occurrence of ftp not just the first one! (In principle, do it for every external command that you might use.)
DON'T modify/delete the rest of the ftp here document!
# 11  
Old 01-20-2015
Hello, could you post a full example please we do not understand. Please.
# 12  
Old 01-20-2015
This is not necessarily wise as
- I don't know your ftp location so would have to use mine which might lead to further confusion.
- It would keep you from finding the solution yourself.

Again:
- use either whereis or type - whichever is available - to get at the ftp location. Post the output.
- replace every occurrence of ftp in your script with your finding. My example in post#8 was the first line of your first ftp here document in your script. Compare the two. And, don't forget the second ftp. Post the resulting script.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

2. Shell Programming and Scripting

Delete files older than 1 year through FTP

Hi All, I want to login to a remote server using FTP command and then check for files older than 1 year and delete those files. Please let me know how can i achieve this using Unix Commands. Thanks in Advance, (10 Replies)
Discussion started by: HemaV
10 Replies

3. Shell Programming and Scripting

Need help creating a script to FTP files to a server and then delete the files that were transfered.

I am trying to FTP files to a Windows server through my Linux machine. I have setup the file transfer with no problems but am having problem deleting those files from the Linux box. My current non-working solution is below. Any ideas, anyone?? :wall: Please be gentle, I'm fairly new to this... (4 Replies)
Discussion started by: jmalfhs
4 Replies

4. Shell Programming and Scripting

how to delete 3 days old files using ftp in a shell script (Solaris OS)

I need help in writng a script to delete last three days files from a remote server using only FTP / SFTP. I was using find command which is not working and i cant use ssh Immediate response is highly appreciated . Thank in advance! ---------- Post updated 12-05-10 at 09:16 PM ----------... (5 Replies)
Discussion started by: Olivia
5 Replies

5. AIX

How to delete information on Storage

Hi, I need some help with two servers, they are running on AIX 5.3, we want to remove and delete all information stored on them because we are no longer to use anymore. The servers are going to be part of donation and we want to be sure that no one can restore information stored on disks or... (1 Reply)
Discussion started by: DBAIX
1 Replies

6. Shell Programming and Scripting

delete old files from FTP server

Hi I just started learning Unix scripts. I need to access an FTP server, delete all the files except the latest 6 files and the latest 6 files should be downloaded to my local server. Could some body help me to code this logic in KSH ? Thanks Athena (1 Reply)
Discussion started by: Athena
1 Replies

7. Shell Programming and Scripting

how to restrict FTP users not to delete their files

Hello all, We have an FTP Server setup with VSFTPd and its working fine without anonymous login (we must maintain this standard) The requirement is to restrict users not to overwrite (and delete) their files. In other words, once their files are uploaded to FTP Server, they should not be... (1 Reply)
Discussion started by: prvnrk
1 Replies

8. UNIX for Dummies Questions & Answers

Reg: delete older files from ftp

Hi, I want to delete older files from ftp server. (files which are more than 5 days old). Please advice Thanks , sam (3 Replies)
Discussion started by: sam99
3 Replies
Login or Register to Ask a Question