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 > 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 and shell scripting languages 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 06:09 AM
How to automate an FTP process? ksak Shell Programming and Scripting 1 10-06-2006 12:45 PM
How to automate responses djp Shell Programming and Scripting 2 06-07-2005 04:00 PM
Automate FTP CamTu UNIX for Advanced & Expert Users 4 02-25-2005 10:08 AM
automate an ftp job flowrats UNIX for Dummies Questions & Answers 11 07-24-2002 08:47 AM

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 05-20-2004
borncrazy borncrazy is offline
Registered User
  
 

Join Date: Apr 2004
Posts: 35
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?
  #2 (permalink)  
Old 05-20-2004
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
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.
  #3 (permalink)  
Old 05-20-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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
  #4 (permalink)  
Old 05-21-2004
borncrazy borncrazy is offline
Registered User
  
 

Join Date: Apr 2004
Posts: 35
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
  #5 (permalink)  
Old 05-21-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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.
  #6 (permalink)  
Old 05-21-2004
borncrazy borncrazy is offline
Registered User
  
 

Join Date: Apr 2004
Posts: 35
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?
  #7 (permalink)  
Old 05-24-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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.
Closed Thread

Bookmarks

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 10:07 PM.


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