FTP'ing the zipped file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP'ing the zipped file
# 1  
Old 05-10-2011
FTP'ing the zipped file

Hi,

I need to have a shell script that FTP's a zipped file from a particular location.

I have some path and inside that path i will have folders like x_timestamp and inside x_timestamp there may many folders based upon events like y_111,y_222,y_333.Inside each event there will be another folder z.

Inside the z only the file to be FTP'd is lying.

And x_timestamp folder will not be deleted as soon as we take the zipped file. So as soon as the file x_20110509 (Say for eg)is FTP'd the next time eventhough the folder x_20110509 is there the script should go for other x_timestamp folder leaving the one which is already FTP'd.

Thanks in advance.
# 2  
Old 05-10-2011
So do you want to pick up newer files of name x_timestamp/y111/z/*.zip? If so, we might be able to achieve it with a two call ftp by using a logging file. Could we consider the following logic:-
  1. List out all the files that fit the criteria, e.g. */*/*/*.zip
  2. Exclude all the files that we already have
  3. Get the remainder
  4. Update the logging file
Would that suit? If so, then perhaps this will help:-
Code:
#!/bin/ksh
#
# Get new files only ftp
# 

source=source.mycompany.com
basesource="/my_source"
search="*/*/*/*.zip"
register=received_files.txt
tempfile=dir_listing.txt
gets=get_commands.txt
username=fred
password=fred

ftp -n $source > $tempfile || -EOFTP
 user $username
 $password
 cd $basedir
 dir $search
 quit
EOFTP

# Okay, we now have a list of all interesting files on the remote source
# We might need to trim this down with head/tail commands depending on the FTP
# server response to just leave the file records.

grep -vf $register $tempfile|while read line
do
   file="${line##* }"      # Get last field, i.e. file name.  Format is hash, hash, asterix, space
   echo get $file
done > $gets

# Now we have the required gets for new or updated files so do the actual transfer

ftp -n $source || -EOFTP
 user $username
 $password
 cd $basedir
 bin                  # If you want a binary transfer for compressed files
 `cat $gets`
 quit
EOSQL

# Update the registered files to show that they have transferred
grep -vf $register $tempfile >> $register

Caveat/warning
I must admit that this has not been tested as I'm not sure of your requirements. There is also no error checking in the ftp transfer, or indeed the script as a whole. There may be some syntax errors, but hopefully this free suggestion may get you started down the right path.



Like I comment in the code, some adjustment may well be needed to exclude directory listing headers/trailers, or perhaps you could just accept errors for the first run then they will get ignored. I hope that this helps, but let us know how you get on and someone else may provide a better suggestion or correct my errors.


Robin
Liverpool/Blackburn
UK
# 3  
Old 05-12-2011
Thanks Robin for the code

Thanks Robin for the code
# 4  
Old 06-08-2011
Hi Robin,

The command dir */*/*/*.zip is not working after logging into FTP

Do we have anyother command that can dynamically get the file names in the above mentioned layers.

Thnx,
Vinoth
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

After Ftp'ing file to destination how to check the file if it is in correct ASCII and not corrupted

Hi Folks, While transferring file from FTP software like Filezilla the files gets corrupted. Is there any way I can check if the recently transferred file is in ASCII and not corrupted. I have tried using file -i filename command which does tell if the file character set is ASCII or binary... (6 Replies)
Discussion started by: Khan28
6 Replies

2. Solaris

FTP-ing files from Windows server to UNIX server

I need to transfer files from a Windows server to the Unix server and have to run some shell script on it to get the required output. Is it possible to transfer files from Windows server to unix server through any shell script? If so can you please help me with the details. Thanks in... (8 Replies)
Discussion started by: ssk250
8 Replies

3. Shell Programming and Scripting

ftp'ing multiple files to the remote server

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

4. Shell Programming and Scripting

grep'ing and sed'ing chunks in bash... need help on speeding up a log parser.

I have a file that is 20 - 80+ MB in size that is a certain type of log file. It logs one of our processes and this process is multi-threaded. Therefore the log file is kind of a mess. Here's an example: The logfile looks like: "DATE TIME - THREAD ID - Details", and a new file is created... (4 Replies)
Discussion started by: elinenbe
4 Replies

5. UNIX for Dummies Questions & Answers

FTP'ing EBCDIC Characters from Mainframe

Hi All, I am new to this site, I have a requirement where in i have to FTP a file from mainframe to Unix box. The catch here is there are few Spanish characters like N with tilde(~) and a with ` etc., all other characters are coming fine but those mentioned above are not coming in a proper... (1 Reply)
Discussion started by: harikiranr
1 Replies

6. Shell Programming and Scripting

size of a file that iam ftp ing

Hi, I want to compare the size of the files in my local machine before ftp ing it and the size of the file in the remote machine i.e after ftping . SO that the ftp is successful . (3 Replies)
Discussion started by: dineshr85
3 Replies

7. UNIX for Advanced & Expert Users

Dynamically ftp'ing a file

Hi, I am having unix script that passes argument value to script. The script finds the file and keeps it in a directory. I need to ftp this file to another server. Please guide me how to acieve this. I am able to connect to ftp server but i am not able to use the unix argument in the ftp... (0 Replies)
Discussion started by: pyaranoid
0 Replies

8. Shell Programming and Scripting

Help in FTP'ing multiple files

Hi, I have written the following FTP script to get the multiple files from remote server to local server. My problem is that 'mget *' is not working in the script. I also tried with 'mget *.txt', 'mget *.*' etc. without any success. It do not copy any file to local server. In the script, Prompt... (10 Replies)
Discussion started by: berlin_germany
10 Replies

9. Shell Programming and Scripting

FTP'ing files with filenames in mail messege

Hi, I have created the following FTP script, which transfers daily “.txt” files from remote server in to a timestamped folder on local server. Once all files are FTP'ed, it then deletes files from remote server. When files are FTP'ed, I get a mail messege like, “Files are successfully transfered”,... (1 Reply)
Discussion started by: berlin_germany
1 Replies

10. IP Networking

Ftp'ing thru a Iptables NAT Masquerade

Greetings to all. My new firewall is giving me one hell of a problem. I'm running iptables and masquerading my intranet thru NAT. But here is the problem. Whenever I try to FTP to a server outside of my lan I get a 500 illegal port error. I've come to the conclusion that NAT is... (2 Replies)
Discussion started by: phrater
2 Replies
Login or Register to Ask a Question