The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 06:35 AM
Transfer file from local unix server to remote server indira HP-UX 2 05-02-2007 05: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 06: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-27-2005 01:53 AM
Running shell scripts on a remote server pepintheshort UNIX for Dummies Questions & Answers 2 07-22-2003 04:20 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-23-2008
sashankkrk sashankkrk is offline
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
  #2 (permalink)  
Old 04-23-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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).
  #3 (permalink)  
Old 04-23-2008
benefactr benefactr is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 71
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.
Closed Thread

Bookmarks

Tags
unix commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0