The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Transfer file from local unix server to remote server indira Shell Programming and Scripting 2 05-03-2007 03:35 AM
Transfer file from local unix server to remote server indira HP-UX 2 05-02-2007 02:15 PM
Can a shell script pull the first word (or nth word) off each line of a text file? tricky Shell Programming and Scripting 5 08-17-2006 03:29 AM
how to move a file from one server to another server using FTP in shell script? forevercalz Shell Programming and Scripting 4 10-26-2005 10:53 PM
Running shell scripts on a remote server pepintheshort UNIX for Dummies Questions & Answers 2 07-22-2003 01:20 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-23-2008
Registered User
 

Join Date: Apr 2008
Posts: 2
Pull a file from a remote server through a shell script

Hi,

I am writing a shell script to pull a file from a remote server (Let say its a windows based remote server). One of my criteria is to pull a file only if it is not empty.

We have done a similar script to push a file from our end to a remote server and before pushing it we check for the file size and only when it is not empty we proceed to ftp the file. This script works fine without any issues.

Here is the sample script for pushing the files to remote server.
----------------------------------------------------------------------
#!/usr/bin/ksh

"Usage: $0 <Server> <USERID> <LOCALFILEPATH> <REMOTEFILEPATH> <FTPTYPE> <FILECHECKER> <FILENAME1> <FILENAME2>...."

#FTPTYPE is either ascii or binary
#FILECHECKER is either Y or N. When Y the script has to check for file size before ftp'ing the file. It has to ftp only if the file size is > 0

#Counting the list of Files to be FTP'ed
shift 6
file_count=$#
echo "Total files to be ftped : ${file_count} "

LOCAL_FILE_LIST=$@
#Get the files that needs to be ftp'ed into a LOCAL_FILE_LIST.


#If File Checker is "Y" check if the files are empty and prepare a new file list
fl_cnt=0

if [ ${FILE_CHECKER} = "Y" ]
then
for flnm in ${LOCAL_FILE_LIST}
do
if [ -s ${flnm} ]
then
FILE_LIST=${FILE_LIST}" "${flnm}
fl_cnt=`expr ${fl_cnt} + 1`
fi
done
else
FILE_LIST=$LOCAL_FILE_LIST
fi
echo $FILE_LIST


if [ ! -z "$FILE_LIST" ]
then
echo "FTP Started"
ftp -n << EOF > $LOG_FILE
verbose
open ${SERVER}
$LOGON
$FTP_TYPE
cd ${REMOTE_FILE_PATH}
mput ${FILE_LIST}
close
bye
EOF
else
echo "Files Empty hence not FTP'd"
exit 0
fi
----------------------------------------------------------------------

Now I am having issues with my pull script, when I connect to the remote server I am not able to execute any shell commands on that server since it is a windows based. Hence I won't be able to check for file size before I pull those files.

Can anyone give some idea's/tips on how to check for file size on remote server or how to execute some shell commands on remote server?

Thanks,
Sashank
Reply With Quote
Forum Sponsor
  #2  
Old 04-23-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
The FTP protocol has commands for getting the file size, but the output format etc was never standardized and what you get from a random Windoze box might be a bit tacky. Anyway, the big problem with using a run-of-the-mill ftp client is that once you have started the client, you can't easily interact with it.

My first suggestion would be to look at more feature-oriented ftp clients such as lftp or ncftp. My second suggestion, half in jest, would be to cobble together your own little simple client from Perl and chewing gum. Probably Python has good libraries for this, too (actually most likely better out of the box than Perl). Unless of course you can install a better server over on the Wintendo box (SSH has the added benefit that it is also secure).
Reply With Quote
  #3  
Old 04-23-2008
Registered User
 

Join Date: Jul 2007
Posts: 53
Quote:
Originally Posted by era View Post
The FTP protocol has commands for getting the file size, but the output format etc was never standardized and what you get from a random Windoze box might be a bit tacky. Anyway, the big problem with using a run-of-the-mill ftp client is that once you have started the client, you can't easily interact with it.

My first suggestion would be to look at more feature-oriented ftp clients such as lftp or ncftp. My second suggestion, half in jest, would be to cobble together your own little simple client from Perl and chewing gum. Probably Python has good libraries for this, too (actually most likely better out of the box than Perl). Unless of course you can install a better server over on the Wintendo box (SSH has the added benefit that it is also secure).
Or when you get the file to the local unix server check for the file size then, if it's empty then remove it.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0