FTP files modified after a particular date between servers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP files modified after a particular date between servers
# 1  
Old 07-22-2010
FTP files modified after a particular date between servers

Hi all,

i need to write a shell script to transfer a file modified after a particular date from one server to another. I searched for the related posts in this forum and got hints and snippets for it. i tried the below code

Code:
ftp serverA
user uname pwd
lcd to_dir
cd from_dir
files=$(find from_dir -mtime -10)
for file in $files
do
get $file
done
bye

This is what i tried. The files are in server A and i am running this script file from server B so tat it will connect to server A and retrieve the files to server B. When i executed the script, i got the error as "Invalid Command" in my log. I am not sure where the error is in the code.

Can someone suggest a solution?

Thanks in advance.
# 2  
Old 07-22-2010
Hi.

Not sure you can put all that shell logic as an FTP program.

I didn't test this, but it might work Smilie

Replace this:
Code:
files=$(find from_dir -mtime -10)
for file in $files
do
get $file
done

With this:
Code:
$(find from_dir -mtime -10 | xargs -n1 echo get)

You might also want to replace:
Code:
ftp serverA

With:
Code:
ftp serverA << !

and
Code:
bye

With:
Code:
bye
!

# 3  
Old 07-23-2010
This task is not impossible with just "ftp" but it is very difficult.

What type of server and Operating System are you transfering from and to?

If they are something easy like a pair of matched unix servers on a LAN, do you have "rcp" or "scp" and some sort of "Remote Shell" configured?

Do you have administrative access to both servers?
# 4  
Old 07-23-2010
Hi,

@scottn

I tried the code changes suggested by you. This time around i am not getting any invalid command error in my log but am not able to transfer files modified after a date.In the log , am not able to get the text "Port command successful". In the find command this is how i gave the source dir path.


Code:
$(find x/y/z -mtime -10 | xargs -n1 echo get)

My files will be in the z folder in the remote server. I am not sure whether it is able to identify the source dir in the remote server. My script file will be in server B and the files to be copied in server A. I am running this script in server B which will connect to A and transfer the files. Kindly suggest a solution.


@methyl

I am trying to connect to 2 unix servers and copy files from a folder in one server to a folder in the other server. I have only read-only permissions in the server from where the files to be transferred are there. In the other server i have full access.


Thanks in advance
# 5  
Old 07-24-2010
Sorry Smilie My post was completely useless because you're getting files, not putting them.

I'm not sure how you could do that with just ftp, except, perhaps if you had a file on the remote server with the list of files to transfer, then you could first transfer that file, and use it as a basis for transferring the other files.

I did a quick test (albeit using SFTP as I don't have - or want FTP):
Code:
$ cat GetFiles
sftp scott@centos64 << !
lcd /Users/scott/scripts/tmp/ftp
cd /tmp/ftp
get files.txt
$(xargs -n1 < files.txt echo get)
bye
!

$ ./GetFiles
Connecting to centos64...
scott@centos64's password:
sftp> lcd /Users/scott/scripts/tmp/ftp
sftp> cd /tmp/ftp
sftp> get files.txt
Fetching /tmp/ftp/files.txt to files.txt
/tmp/ftp/files.txt                                                                                100%   42     0.0KB/s   00:00    
sftp> get ./a/fileA
Fetching /tmp/ftp/./a/fileA to fileA
/tmp/ftp/./a/fileA                                                                                100%    8     0.0KB/s   00:00    
sftp> get ./files.txt
Fetching /tmp/ftp/./files.txt to files.txt
/tmp/ftp/./files.txt                                                                              100%   42     0.0KB/s   00:00    
sftp> get ./c/fileC
Fetching /tmp/ftp/./c/fileC to fileC
/tmp/ftp/./c/fileC                                                                                100%    8     0.0KB/s   00:00    
sftp> get ./b/fileB
Fetching /tmp/ftp/./b/fileB to fileB
/tmp/ftp/./b/fileB                                                                                100%    8     0.0KB/s   00:00    
sftp> bye

$ ls
GetFiles fileA fileB fileC files.txt

If you need the PATHS locally too, you would need some extra work.


Otherwise, the scp route is maybe the best option.

Last edited by Scott; 07-24-2010 at 06:03 AM..
# 6  
Old 07-24-2010
Hi,

I don't have the name of the files to transfer from remote server. I need to get those files which were modified after a particular date. I tried using the ssh command. I tried connecting to the remote server using the ssh command to copy files modified after a date from that server to my current server.
This is what i tried:

Code:
ssh username@hostname <<EOT
cd /x/y
find . -mtime -1 -type f |\
while read file
do
echo $file
scp -rp $file username@hostname:/a/b/c/$file
done
EOT

The modified file names are getting printed in the screen from the echo cmd. But while transferring the files using scp cmd, it gives an error that it is not able to identify the target path. Is there a solution to it?
# 7  
Old 07-24-2010
You're trying to scp from the remote server.

Code:
ssh root@centos64 <<EOT > files.txt
cd /tmp/ftp
find . -type f
EOT

while read FILE; do
  mkdir "${FILE%/*}" 2> /dev/null
  scp -p root@centos64:/tmp/ftp/"'$FILE'" "$FILE"
done < files.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to copy creation date over top of modified date?

Can someone draw up a script that for every file, folder and subfolder and files that will copy the creation date over top of the modified date?? I know how to touch every file recursively, but no idea how to read a files creation date then use that to touch the modification date of that file,... (3 Replies)
Discussion started by: toysareforboys
3 Replies

2. Shell Programming and Scripting

How to find all files modified from midnight (i.e. from midnight (00:00:00)) of current date?

Hi there! I was wondering if someone could help me with the following: I'm trying to find all files within a directory which have been modified since midnight of the current date. Any help would be appreciated. Thank you kindly. (6 Replies)
Discussion started by: Jimmy_the_tulip
6 Replies

3. Shell Programming and Scripting

Ftp files with date

Hi, i need to put files with current date at end from one server to another. i.e. all the output files from below comand. ls -ltr `date '+monthly_stats.sh%y%m%d'` am using mput `date '+monthly_stats.sh%y%m%d'` but no files are transfered Connected to gbdsnh18.hartfordlife.com. 220... (5 Replies)
Discussion started by: Simanto
5 Replies

4. Shell Programming and Scripting

How to get the files which has modified date as yesterday and before?

Hi All, Can you please help me to get only the files which has the modified date as yesterday and before? Thanks in advance! Regards, Velava.S (4 Replies)
Discussion started by: velava
4 Replies

5. Emergency UNIX and Linux Support

Is there any way to set the files modified date and stamp to last modifies time?

Actually i did modification in a file on server by mistake, now its showing current time stamp, is there any way to set the files modified date and stamp to last modifies time. Please advice here.Thanks in advance.:b: (7 Replies)
Discussion started by: saluja.deepak
7 Replies

6. UNIX for Dummies Questions & Answers

mv folders/files without changing modified date?

Hi all, I'm using Red Hat Linux and want to move some folders and files around but not change the modified date. Is this possible? I know cp has a -p flag which seems to do what I want, but this is a large volume of data so copying and deleting would not be feasible. (13 Replies)
Discussion started by: Annorax
13 Replies

7. UNIX for Dummies Questions & Answers

Number of files in a directory modified on a date

Hi How to list all the files in a directory that are modified on a particular date? Also need to know the count,i.e number of files modified on a particular date. Thanks Ashok (1 Reply)
Discussion started by: ashok.k
1 Replies

8. UNIX for Dummies Questions & Answers

Find last modified date for many files

Hello all - I've looked and have not been able to find a "find" command that will list the last modified date of files within a specific directory and its subdirectories. If anyone knows of such a command it would be very much appreciated! If possible, I would like to sort this output and have... (5 Replies)
Discussion started by: MichaelH3947
5 Replies

9. UNIX for Dummies Questions & Answers

Create a list of files that were modified after a given date.

Hello Mates! I'm kinda new to unix and need to a solve a problem. Input: date Situation: With the given date I need to find a list of all such files starting from a given path that were modified after the given date. I experimented with the "find" with "-newer" but did not quite get it... (4 Replies)
Discussion started by: rkka
4 Replies

10. Linux

compare files in the system with last modified date

HI, I have some files in my Linux machine that are very old and occupy a HUGe amount of space. I am trying to delete these files from the system so that it will be easy for me to add some files. I would like to know if this can done through a Perl or a shell script. What i want to do is i... (6 Replies)
Discussion started by: bsandeep_80
6 Replies
Login or Register to Ask a Question