![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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). |
|
||||
|
Quote:
|
![]() |
| Bookmarks |
| Tags |
| unix commands |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|