The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
automate Telnet ? tbeghain Shell Programming and Scripting 4 06-19-2007 03:09 AM
How to automate an FTP process? ksak Shell Programming and Scripting 1 10-06-2006 09:45 AM
How to automate responses djp Shell Programming and Scripting 2 06-07-2005 01:00 PM
Automate FTP CamTu UNIX for Advanced & Expert Users 4 02-25-2005 06:08 AM
automate an ftp job flowrats UNIX for Dummies Questions & Answers 11 07-24-2002 05:47 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-20-2004
Registered User
 

Join Date: Apr 2004
Posts: 35
Stumble this Post!
Question Automate FTP

Hi,

Currently, i am using sftp manully to transfer files between two secure servers. Can anyone provide me a sample shell script which can automate the sftp process?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-20-2004
google's Avatar
Moderator
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Stumble this Post!
Hate to be short, but use the search button (upper right hand corner over there!). There are a tremendous amount of examples on this board.
Reply With Quote
  #3 (permalink)  
Old 05-20-2004
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,444
Stumble this Post!
I have finally added a post in the faq section on automated ftp.

Navigate

our home page -> Answers to Frequently Asked Questions -> Automate FTP / Scripting FTP Transfers
Reply With Quote
  #4 (permalink)  
Old 05-21-2004
Registered User
 

Join Date: Apr 2004
Posts: 35
Stumble this Post!
Smile

Perderabo

The information provided was awesome. Being a begginner in Unix, a lot of stuff was difficult for me to understnad. Just wanted to enquire whether the script can be used to include 'SFTP' instead of 'FTP'.

Thanks
Reply With Quote
  #5 (permalink)  
Old 05-21-2004
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,444
Stumble this Post!
Yeah, but you'll need to adjust the script so that it answers the questions sftp asks. Just run sftp by hand and make a note of what you do. Then adjust the script accordingly. Or have the script in a second window and adjust it as you run.
Reply With Quote
  #6 (permalink)  
Old 05-21-2004
Registered User
 

Join Date: Apr 2004
Posts: 35
Stumble this Post!
Unhappy

Perderabo,

I made few modifcations to your script to incorporate sftp instead of ftp. I am getting the following error

$ ./coolFtp.sh
$ Warning: tcsetattr failed in ssh_rl_set_tty_modes_for_fd: fd 1: I/O error

The script i am using is :

HOST=<Ip Address>
USER=<user>
PASSWD=<pswd>

exec 4>&1
sftp >&4 2>&4 |&

print -p open $HOST
print -p user $USER $PASSWD
print -p cd rksample
print -p binary
print -p lcd
print -p lcd rktest
print -p put rkftp.txt

exit

Am i doing anything wrong here?
Reply With Quote
  #7 (permalink)  
Old 05-24-2004
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,444
Stumble this Post!
sftp does not support "open" or "user" commands. At least mine does not. I tried the script that you posted. I get a usage statement. This means that my sftp is different than yours and I won't be able to spoonfeed you a answer.

My sftp is unwilling to accept a password via stdin. It seem to open /dev/tty and do a read. I have to arrange for ssh to work without a password. This involved running "ssh-keygen -t rsa". Then I had to copy my ~/.ssh/id_ra.pub file into my .shh/authorized_key2 file on the ftp server. Then on the client system, I ran ssh-agent and used ssh-add to add the new identity. At this point, both ssh and sftp to the ftp server worked without asking for a password.

At this point, this script worked:
Code:
 #! /usr/bin/ksh
exec 4>&1
sftp ${USER}@${HOST} >&4 2>&4 |&
print -p get testfile
print -p bye
wait
exit 0
But looking at the manpage for sftp I see that it also supports a batchfile option. That may be another approach worth persuing.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




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


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

Content Relevant URLs by vBSEO 3.2.0