Sponsored Content
Operating Systems Linux Get all the files from a FTP location with previous week's dates in the file names using Linux Post 302851817 by spacebar on Monday 9th of September 2013 05:39:13 PM
Old 09-09-2013
This is an example script script that creates a 'ftp' script that 'puts' the files from the last sunday thru saturday to remote host:
Code:
echo 'ftp -vn FTP2 <<ENDSCRIPT' >>ftp_script.sh
echo 'user userid pass' >>ftp_script.sh
echo 'cd /path/to/dir' >>ftp_script.sh
echo 'lcd /path/to/dir' >>ftp_script.sh
echo put Sales_`date -d '-8day' +%Y%m%d`_report.csv >>ftp_script.sh
echo put Sales_`date -d '-7day' +%Y%m%d`_report.csv >>ftp_script.sh
echo put Sales_`date -d '-6day' +%Y%m%d`_report.csv >>ftp_script.sh
echo put Sales_`date -d '-5day' +%Y%m%d`_report.csv >>ftp_script.sh
echo put Sales_`date -d '-4day' +%Y%m%d`_report.csv >>ftp_script.sh
echo put Sales_`date -d '-3day' +%Y%m%d`_report.csv >>ftp_script.sh
echo put Sales_`date -d '-2day' +%Y%m%d`_report.csv >>ftp_script.sh
echo quit >>ftp_script.sh
echo 'ENDSCRIPT' >>ftp_script.sh
echo 'rc=$?' >>ftp_script.sh
echo 'if [[ $rc != 0 ]];    then' >>ftp_script.sh
echo '  echo "Error occured...$rc" `date "+%Y-%m-%d-%H.%M.%S"`' >>ftp_script.sh
echo 'else' >>ftp_script.sh
echo '  echo "Successful transfer...$rc" `date "+%Y-%m-%d-%H.%M.%S"`' >>ftp_script.sh
echo 'fi' >>ftp_script.sh

Code:
$ cat ftp_script.sh
ftp -vn FTP2 <<ENDSCRIPT
user userid pass
cd /path/to/dir
lcd /path/to/dir
put Sales_20130901_report.csv
put Sales_20130902_report.csv
put Sales_20130903_report.csv
put Sales_20130904_report.csv
put Sales_20130905_report.csv
put Sales_20130906_report.csv
put Sales_20130907_report.csv
quit
ENDSCRIPT
rc=$?
if [[ $rc != 0 ]];      then
  echo "Error occured...$rc" `date "+%Y-%m-%d-%H.%M.%S"`
else
  echo "Successful transfer...$rc" `date "+%Y-%m-%d-%H.%M.%S"`
fi

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

transferring files using ftp but mantaining the dates

Hi guys, Is there a way I can ftp some files without changing the last-modified dates from them ? I haven't seen any ftp option to do so. Or, alternatively, how do I change the last-modified date for a file, if this is possible... ? Thanks in advance, Abrahao. (4 Replies)
Discussion started by: 435 Gavea
4 Replies

2. Shell Programming and Scripting

grep a log file to filter previous dates

Hi, I have problem of filtering a log file from my perl script. #cat /data/pinpe.csv_20070731 | nawk -v FS=, '{print $1','$18','$22','$26}' | grep -w 100 | grep -w 1 | nawk '{print $4}' Below is the output: 2009-06-16 2009-01-29 2009-06-02 2008-03-05 2007-08-05 2007-09-24... (5 Replies)
Discussion started by: pinpe
5 Replies

3. Shell Programming and Scripting

Get Files from ftp which are uploaded recent week

Hi All, Here is a brief scenario for my requirement .. There is a directory in FTP Server, where would files be uploaded on weekly basic. I need to get those files which are uploaded during this week and not the files which are uploaded the previous week and download them to locale... (1 Reply)
Discussion started by: narramadan
1 Replies

4. Shell Programming and Scripting

how to put file from one ftp to another ftp location

hi, I have one file located in ftp.I want to place that file in different ftp location. Up to now i am doing it manually using get command and copying that file in to my local system and then putting that file in different ftp using put command. now i want to automate that using shell... (1 Reply)
Discussion started by: prasee
1 Replies

5. UNIX for Dummies Questions & Answers

Checking files in ftp location

I am having a requirement to check whether files were there in the ftp location and if the files were not there then need to send a mail to someone.Suppose there were files like A,B,C,D,etc.. if the file A was not there then mail to someone similarly for all the files. Thanks for your help. ... (2 Replies)
Discussion started by: nimu1979
2 Replies

6. UNIX for Dummies Questions & Answers

Device Files names and location

HI there. I am studying System administration right now and am stuck on a question that I have failed to find the answer for in my book. The question is: Do device files need to be in the /dev directory and to they need to follow a naming convention? My answer (so far) is that since the... (7 Replies)
Discussion started by: Carl1976
7 Replies

7. Shell Programming and Scripting

Download previous day files through FTP

Hi All, I have a scenario where I need to download the previous day modified files from other server to my server through FTP . Could any one please send me the shell script for the same. I used the following but I dont know how to proceed after this. ftp -n -i -v $IP <<ENDOFinPUT >>... (3 Replies)
Discussion started by: sarathchandrach
3 Replies

8. Shell Programming and Scripting

How to get the dates from a list of file names?

Hi All, I have a .txt file with the list of filenames as given below. /dev_data/dev3/ctl/20120622_Employee.txt /dev_data/dev3/ctl/20120623_Employee.txt /dev_data/dev3/ctl/20120624_Employee.txt I want to read this file & write the dates alone from the filenames into a .done file. ... (6 Replies)
Discussion started by: dsfreddie
6 Replies

9. Shell Programming and Scripting

Need Help:Shell Script for Solaris to change the dates in a file by one week

I have to increase the date by one week in an input when script is executed in solaris. I was able to acheive this using ksh script that is working in Linux enivironment, when i execute the same script in Solaris i am getting below error: /var/tmp\n\r-> ./script.ksh date: illegal option -- d... (3 Replies)
Discussion started by: sriramanaramoju
3 Replies

10. Shell Programming and Scripting

Remove dates from file names

Hi, I'm using a shell script. I have extracted current date files to a directory1 and the date should be removed on both sides of a CSV file. FYI... I'm looking to remove the date from the file name and not inside the CSV file. Directory1 2017-07-12_gmr_tag_log_20170711.csv... (0 Replies)
Discussion started by: shivamayam
0 Replies
ftp::geturl(n)							    ftp client							    ftp::geturl(n)

__________________________________________________________________________________________________________________________________________________

NAME
ftp::geturl - Uri handler for ftp urls SYNOPSIS
package require Tcl 8.2 package require ftp::geturl ?0.2.1? ::ftp::geturl url _________________________________________________________________ DESCRIPTION
This package provides a command which wraps around the client side of the ftp protocol provided by package ftp to allow the retrieval of urls using the ftp schema. API
::ftp::geturl url This command can be used by the generic command ::uri::geturl (See package uri) to retrieve the contents of ftp urls. Internally it uses the commands of the package ftp to fulfill the request. The contents of a ftp url are defined as follows: file The contents of the specified file itself. directory A listing of the contents of the directory in key value notation where the file name is the key and its attributes the asso- ciated value. link The attributes of the link, including the path it refers to. BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category ftp of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. SEE ALSO
ftpd, mime, pop3, smtp KEYWORDS
ftp, internet, net, rfc 959 CATEGORY
Networking ftp 0.2.1 ftp::geturl(n)
All times are GMT -4. The time now is 01:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy