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.
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:-
List out all the files that fit the criteria, e.g. */*/*/*.zip
Exclude all the files that we already have
Get the remainder
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.
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)
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)
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)
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)
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)
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)
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)
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)
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)