UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old September 29th, 2004, 12:54 PM
shal shal is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 1 shal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How to code script for transferring filr from unix to some remote server.

Hello,

I am new to unix and need some help in coding a script which does two things:
1) Appends current date to file name
2) Transfers this renamed file from unix to some remote server.

Any leads on this will be helpful.

Thanks,
Shal

Reply With Quote
  #2  
Old September 29th, 2004, 01:19 PM
andyb1ack andyb1ack is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 60 andyb1ack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 14 sec
Reputation Power: 4
Hi Shal,
Let me know how you get on with this.
Check out post "ftp in ksh program" by viswapsp below too...
Andy

You can amend in time to accept the remote node, the destdir, and maybe the username and password.

I think you'll always going to get a zero exit code from the ftp even if the file doesn't get transferred so don't rely on the exit code to determine if it's worked.

Code:
#!/usr/bin/ksh

#-- Set variables
FILE=$1                              # the first parameter on the command line
CURRDATE=`date +%Y%m%d`
REMOTENODE=node_to_ftp_file_to
USERNAME=unix_account_on_remote_node
PASSWORD=password_of_unix_account
DESTDIR=destination_directory_for_file

#-- Check a file has been passed as a parameter to this script
if [[ -z "${FILE}" ]]; then
  echo ERROR: file to process not passed
  exit 10
fi

#-- Check the file exists
if [[ ! -f ${FILE} ]]; then 
  echo ERROR: ${FILE} does not exist or is not a regular file
  exit 20
fi

#-- Rename file
mv ${FILE} ${FILE}.${CURRDATE}

#-- Get the filename of the FILE
FILENAME=`basename ${FILE}`

#-- Ftp the file
ftp <<END_OF_FTP
open ${REMOTENODE}
quote user ${USERNAME}
quote pass ${PASSWORD}
hash
put ${FILE} ${DESTDIR}/${FILENAME}
dir ${DESTDIR}/${FILENAME}
bye
END_OF_FTP

exit

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > How to code script for transferring filr from unix to some remote server.


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway