To check wheather a file is downloaded completely or not

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To check wheather a file is downloaded completely or not
# 1  
Old 09-01-2010
To check wheather a file is downloaded completely or not

I will have two files (which were in .txt format) ftp'ed to a specified directory, from where my ksh picks up each file at a time and starts processing it. So i need to write a script which as soon as find a file should check wheather it is download completely or not. If it is still downloading then it should wait till the file downloads completely, once it is downloaded completely then it should go to next step. Any help is greatly appreciated.

Thank you
# 2  
Old 09-01-2010
I suggest you to use some mechanism to communicate to that ksh script about the completion of download.

Or else, check the size or md5sum of the file for the completion.
# 3  
Old 09-01-2010
Hi VPV0002,

We have two options:
1. Use the function below which will base on the file size:


transfFileFinished ()
	if [ ! -f "${valFilePath}" ]
		echo "ERROR: File does not exist: [${valFilePath}]. Exit 1."
		exit 1
	oldFileSize=`ls -l "${valFilePath}" | awk '{print $5}'`
	while true
		if [ ${numOfRetries} -eq 0 ]
			echo "File transfer ok. Max number of retries reached: [${numOfRetries}]"
			return 0
		currFileSize=`ls -l "${valFilePath}" | awk '{print $5}'`
		if [ ${oldFileSize} -eq ${currFileSize} ]
			# If reaches here ${numOfRetries} times, so the file is ok
			numOfRetries=`expr ${numOfRetries} - 1`
			echo "File size differ. Old File Size: [${oldFileSize}] - Curr File Size: [${currFileSize}]."
		echo "Old File Size: [${oldFileSize}] - Curr File Size: [${currFileSize}] - Retry: [${numOfRetries}] - Sleeping: [${sleepTime}]..."
		sleep ${sleepTime}
		oldFileSize=`ls -l "${valFilePath}" | awk '{print $5}'`

transfFileFinished "./TestFile.txt"

2. From where you are sending the file, send the file with a ".tmp" in the end of the filename and after the transfer finished, use the FTP rename command and rename it to the original filename, so your ksh script will process it.

Hope it helps.


Last edited by felipe.vinturin; 09-01-2010 at 05:38 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] Downloaded file is not correct format

Hi, Recently we migrated an application in HP UX to Linux. The files(scripts & logs)download from HP UX coming in a formatted way in MS notepad. However the files in Linux are not in correct format in MS notepad(No spaces , some spl symbols like square).We tried both ASCII and binary but no... (2 Replies)
Discussion started by: nag_sathi
2 Replies

2. Shell Programming and Scripting

extract fields from a downloaded html file

I have around 100 html files and in each html file I have 5-6 such paragraphs of a company and I need to extract the Name of the company from either the one after "title" or "/company" and then the number of employees and finally the location . <div class="search_result"> <div... (1 Reply)
Discussion started by: gubbu
1 Replies

3. Programming

how to copy downloaded file into my source file folder (putty/unix)

I need to "Ensure that when you download libchat.a from the VLE you have copied it to the same folder on ius as your source files. You then refer to the library (and the libraries it needs) with: gcc -o outputfile sourcefile.c -L. -lchat -lsocket -lnsl" But I have no idea what this means! (I... (2 Replies)
Discussion started by: fakuse
2 Replies

4. UNIX for Advanced & Expert Users

script to check if file was downloaded

I want to create a script to check if a file was downloaded into a folder. if it was i dont want to re-download it. The requirement is as follows. The first time the file (filename: A) is downloaded, it is renamed by stripping off part of the filename to filename A22. The second time an... (1 Reply)
Discussion started by: wizardofoz
1 Replies

5. UNIX for Advanced & Expert Users

Check EOF char in Unix. OR To check file has been received completely from a remote system

Advance Thanks. (1) I would like to know any unix/Linux command to check EOF char in a file. (2) Or Any way I can check a file has been reached completely at machine B from machine A. Note that machine A ftp/scp the file to machine B at unknown time. (5 Replies)
Discussion started by: alexalex1
5 Replies

6. Shell Programming and Scripting

Check if file is loaded completely and then process the file

I need to write a script which checks for files loaded into a folder (files are loaded by ftp from other server) and process the file only if the file is loaded completely. if the file is not complete in the current run, it must be processed in the next run. Any suggestions would be welcome... (2 Replies)
Discussion started by: kalyan381
2 Replies

7. 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

8. UNIX for Advanced & Expert Users

Using FTP to check whether file is completely FTP... plz find the description below

Hi, We have some clients who will place huge files in to one of the remote server. And the shell script written in our local server to retrieve client files (using FTP) placed on one of the remote server of ours by clients. My question Is there any FTP command/script to check from my local... (1 Reply)
Discussion started by: nmsrao
1 Replies

9. Linux

How I will check wheather my linux benchmark results are OK

My system bench mark results INDEX VALUES TEST BASELINE RESULT INDEX Arithmetic Test (type = double) 2541.7 876123.7 344.7 Dhrystone 2 without register variables 22366.3 5411602.3 ... (1 Reply)
Discussion started by: chandra s
1 Replies

10. UNIX for Dummies Questions & Answers

HELP! Accidentally downloaded .gz file non-binary

Let me start by saying I am at a VERY beginner level in terms of UNIX/FTP/etc. Someone loaded a file onto a server for me and zipped it using gzip. I accidentally downloaded the file without using "binary". I now have a "filename.txt.gz" sitting on my computer that I need to unzip. Is... (2 Replies)
Discussion started by: UDcc123
2 Replies
Login or Register to Ask a Question

Featured Tech Videos