Sponsored Content
Top Forums Shell Programming and Scripting Deleting multiple files off an ftp server once they have been downloaded Post 302936387 by sph90457 on Wednesday 25th of February 2015 07:09:35 AM
Old 02-25-2015
RedHat Deleting multiple files off an ftp server once they have been downloaded

Hello,

I have a server that I have to ftp files off and they all start SGRD and are followed by 6 numbers.

Code:
SGRD000001
SGRD000002
SGRD000003

The script I have will run every 10 mins to pick up files as new ones will be coming in all the time and what I want to do is delete the files I have picked up from the ftp site as I don't want to keep downloading the same files.

Once I have downloaded the files I need to rename them. Before the renaming process I have done an ls SGRD* > Myfile on the files I have downloaded and then run a loop to put delete in front of the file names.

Myfile contents
Code:
delete SGRD000001
delete SGRD000002
delete SGRD000003

Is there anyway that I can run the commands within Myfile on the ftp server so that I just delete the files I downloaded ?

Another question I have is, is it possible to move the files that I have downloaded into a backup folder on the ftp server or do I have do download the files and upload them back to the ftp server ?

I tried rename in various different ways and it didn't work with multiple files.

Last edited by rbatte1; 02-25-2015 at 10:30 AM.. Reason: Added ICODE tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

deleting multiple files through ftp

Hi, I have a situation where I need to delete multiple files from a folder once I connect to FTP server. I am using ftp script to get the files, number of files always vary from 1 to 100. once I get the files I need to delete all the files downloaded I am making a list of all the files... (4 Replies)
Discussion started by: mgirinath
4 Replies

2. UNIX for Advanced & Expert Users

question regarding ftp. Files downloaded are of size Zero.

I need to download some files from a remote server using ftp. I have ftp'd into the site. I then do an mget * to retrieve all of the data files. Everything seems to proceed normally and I am given feedback that the files were downloaded. Now if I go into the DOS Shell or Windows explorer, it list... (5 Replies)
Discussion started by: ralphisnow
5 Replies

3. Shell Programming and Scripting

FTP multiple files from remote server to local server

Hi, I am facing a weired problem in my FTP script. I want to transfer multiple files from remote server to local server everyday, using mget * in my script. I also, want to send an email for successful or failed FTP. My script works for file transfer, but it don't send any mail. There is... (2 Replies)
Discussion started by: berlin_germany
2 Replies

4. UNIX for Advanced & Expert Users

Count total file downloaded using FTP

Hi All, I'm developing a FTP script as below: ftp -v -n <IP_ADDRESS> << EOF user avery jSqaqUU2 lcd /directory/folder/ ascii prompt mget * bye EOF I would like to enhance the script to count the total file downloaded. For example, once the script run i want the message "Total <n>... (1 Reply)
Discussion started by: cas553
1 Replies

5. Shell Programming and Scripting

Need help in deleting old files from a ftp server

Hi, I'm quite new to unix and perl scripting and need to write a script to delete files older than 7 days from a remote ftp server. Unix or Perl script would do... I wrote the following code: #!/usr/local/bin/perl use File::Basename; use Net::FTP; #use Net::FTP::File; my $verbose =... (15 Replies)
Discussion started by: arunsoman80
15 Replies

6. UNIX for Advanced & Expert Users

why file automatically deleting in ftp server

Iam putting file in ftp server. iam doing ftp to transfer a file to ftp server but after sometime(10 sec) the file is automatically deleting in the ftp. Can i know why this happens. When my friend ftp the file to the same server , the file is not deleting aftersometime... it is there. Can... (1 Reply)
Discussion started by: nani1984
1 Replies

7. Shell Programming and Scripting

ftp'ing multiple files to the remote server

unix shell script (2 Replies)
Discussion started by: giridhar276
2 Replies

8. Shell Programming and Scripting

FTP multiple files from one server to one server

Hi, I'm new to shell script..I have one requriement like - In one server have more than one files,I want to ftp those files to some otehr server.. Ex : test1.pdf test2.pdf Please suggest me how to do (3 Replies)
Discussion started by: venkaswa
3 Replies

9. Shell Programming and Scripting

Renaming Multiple Files in FTP Server

Hi Friends, I have a requirement to get multiple files from ftp(remote) server and once the files is copied to local machine , I need to move the files on to a different directory in ftp machine. FTP Machine : 9.9.999.999 Source File Directory : /ftpuser File Pattern: TMS* Now I have... (1 Reply)
Discussion started by: lokeshbao87
1 Replies

10. Shell Programming and Scripting

Deleting local server file from automated FTP script

Hi, I want to delete a file on the local server, while connected to remote server through FTP. I am using the below code for this $FTP_CMD -v -n $HOST <<*! >> $LOGFILE 2>&1 user $USER $PASSWORD cd $DIR ... (11 Replies)
Discussion started by: jhilmil
11 Replies
ftpcopy(1)						      General Commands Manual							ftpcopy(1)

NAME
ftpcopy - mirror or copy files from a FTP server SYNOPSIS
ftpcopy ftp://host[:port]/directory [local-directory] or ftpcopy host[:port] /directory [local-directory] DESCRIPTION
ftpcopy copies a FTP site recursivly. It afterwards deletes all files in the local directory tree which were not found on the remote site. local-directory defaults to "." - the current working directory - if the -n (--no-delete) option is used. local-directory is not needed if the --interactive option is used. Otherwise you must provide a local-directory argument. OPTIONS
Login options -u, --user=NAME Use NAME to login on the ftp server. The default is `anonymous'. Use an empty name to force to not log in. -p, --pass=PASSWORD Use PASS as password to login on the ftp server. The default is `anonymous@invalid.example'. Use an empty password to enforce not sending any password. --account=ACCOUNT Send ACCOUNT as the account name using the ACCT ftp command if the ftp servers asks for one. ACCOUNT in ftp speak is some kind of sub account in some other terminologies. If you don't understand what it means you have a good chance to never need this option anyway. If you think you need it please try the -u option first. --tries=NUMBER Number of tries to connect and log in. The default is 1, meaning that ftpls will give up after the first error. This option was added in version 0.3.0. --login-sleep=NUMBER ftpcopy will sleep for NUMBER seconds after a try to connect or login has failed. The default is 5, a zero is treated as one, and abuse (especially together with --tries) is likely to annoy the server administrator. This option was added in version 0.4.5. Verbosity Options -l, --loglevel=NUMBER this controls the amount of logging done: * 0: nothing except warnings and error messages * 1: downloads and deletes * 2: links/symlinks created, files we already got * 3: useless stuff The default is 1. --bps Log transfer rates. This option was added in version 0.3.9. Options controlling file selection -m, --max-days=NUMBER Download only files modified in the last NUMBER days. Locally existing copies of the not downloaded files will be kept. --max-size=BYTES Download only files up to BYTES bytes length. Locally existing copies of overlong files will be deleted during the clean-up step. This option was added in version 0.5.1. -x, --exclude=WILDCARD Exclude files and directories matching WILDCARD (note that this means shell style wildcards, not regular expression like those of grep). You can repeat this option as often as you want. You can intermix it with the -i option. See IN/EXCLUDE, below, for more information. This option was added in version 0.3.0. -i, --include=WILDCARD Include files and directories matching WILDCARD. You can repeat this option as often as you want. You can intermix it with the -x option. See IN/EXCLUDE, below, for more information. This option was added in version 0.3.0. --ignore-size Do not compare file sizes when checking the remote file has to be downloaded. This option was added in version 0.4.4. --ignore-time Do not compare file modification times when checking the remote file has to be downloaded. This option may be combined with --ignore-size, in which case a file will never be downloaded regardless of changes in file size or modification time. In other words: ftpcopy will not download any updates. This option was added in version 0.4.4. --max-depth Descend at most LEVEL directories deep. 0 means do not enter sub directories at all, 1 means enter sub-directories, but not their sub-directories, and so on. The default is 2^32-1, meaning enter all. This option was added in version 0.5.2. Deletion options -n, --no-delete Do not delete files. This influences the cleanup step at the end, when ftpcopy removes files not found on the server. It doesn't stop ftpcopy from deleting files when it detects something in it's way during a download. -m, --max-deletes=COUNT Do not delete more then COUNT files. This option may be useful to limit the impact of a tempoary loss of files on the server. The default is 0, meaning unlimited. This, too, only influences the cleanup step. This option was added in version 0.4.5. Operational options -d, --directories-only Only create the directory hierarchie, do not download files. Any file in the tree will be deleted unless the -n option is also given. Note: if the -s option is also given then even symbolic links to files will be created (without the files, of course). --dry-run Do not copy or delete files: Only show what would be done. This option was added in version 0.3.6. -T, --timeout=SECONDS Timeout to use for network read/write and connect operations. The default is 30 seconds and is usually sufficient. This option was added in version 0.3.8. --rate-limit BYTES_PER_SECOND Limit the transfer rate of file downloads to about that many bytes per seconds. The implementation is crude and simple, by sleeping up to one second between network reads, and therefore does not even try to limit the rate exactly to that number. On the other hand it usually works and is unlikely to break things by causing timeouts. This option was added in version 0.4.7. --interactive This option tells ftpcopy to ignore any directories given on the command line, and to read commands from the standard input. Each command consists of two lines, the first being a directory on the remote server, and the second a local directory. ftpcopy will print an END-OF-COPY line after each operation. This option was added in version 0.3.6. Workaround options or "things you may need in a less than perfect world": --ascii-listings Do directory listings in ASCII mode instead of binary mode. Use this option if the FTP server is unable to correctly list directories in binary mode, for example, if you see a message like this (outside this manual page this usually comes on one line): ftpcopy: fatal: received unwanted answer to LIST: 426 Data connection: Illegal seek. This option was added in version 0.5.2. -L, --list-options=OPTS Add OPTS to LIST command. This allows to pass arbitrary options to the FTP servers LIST command. Note that ftpcopy does not cope well with recursive directory listings. This option was added in version 0.3.0. -s, --symlink-hack Deal with symbolic links. This is only useful to mirror sites which create listings through /bin/ls. This will fail if a file name in a link contains a ` -> ' sequence. --force-select Do not use the poll() system call even if it's available, but use select(). This allows ftpcopy to be used together with the runsocks program from the socks5 reference implementation. Please note that you'll need a directly reachable name server anyway, as the DNS library in use does not support SOCKS (you can always use IP addresses). This option was added in version 0.3.8. --mdtm Use the MDTM FTP command to determine file modification time. The default is to take the times from the directory listings. This doesn't work if the server implements an inferior listing format (most do) and doesn't send time stamps in universal coordinated time (UTC). This option makes ftpcopy send a MDTM command for any file it might want to download. The drawback is that this eats performance: ftpcopy usually sends just one command for a complete directory its traverses. With the --mdtm option it has to send an additional command for any file. This option was added in version 0.3.10. --tolower Change all local file names to lower case. Use this only if you are absolutely sure that the remote side doesn't contain any files or directories whose names collide with each other. Otherwise this will waste bandwidth. This option was added in version 0.3.8. REMOVED OPTIONS
-R, --remove-dir --keep-dir These options have been added in version 0.3.0 and removed in 0.3.7. --keep-dir made ftpcopy keep a local directory even if it had been replaced by a link to an other directory or a file, --remove-dir did exactly the opposite. --keep-dir was the default for historical reasons. The current behaviour is like that of --remove-dir: ftpcopy creates a copy of the remote ftp site. IN
/EXCLUDE In- and exclude lists are internally mixed together, keeping the order in which they were given. The list starts with an implicit `include *'. ftpcopy honors the last match. The wildcard matching is done against the full remote path of the file. The / character has no special meaning for the matching: it is treated like any other. Note: you have to include top level directories of files or directories you want to include. Something like this will not work: --exclude "*" --include "/w/h/e/r/e/file.c" You need to include /w, /w/h and so on. EXAMPLES
mirror cr.yp.to ftpcopy --exclude '*.cdb' --exclude '*software/precompiled*' cr.yp.to / /private/file/0/mirror/cr.yp.to This means: * i'm not interested in .cdb files. * precompiled stuff is also not downloaded. * the host to connect to is cr.yp.to. * the remote directory is /. * and /private/file/0/mirror/cr.yp.to is the local directory. AUTHOR
Uwe Ohse, uwe@ohse.de SEE ALSO
ftpls(1), ftpcp(1). The homepage may be more up-to-date, see http://www.ohse.de/uwe/ftpcopy.html. ftpcopy 0.5.2 ftpcopy(1)
All times are GMT -4. The time now is 05:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy