LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-26-2009, 04:43 AM   #1
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Rep: Reputation: 55
ftp commands in shell script


hi all........

ftp localhost
ls
quit

i am trying to run above script ...

when i try to run it will ask for passwd and it will login correctly...

but in ftp> prompt ls and quit is not executing ...can anyone help me please....

Thanks in advance
 
Old 05-26-2009, 04:51 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You have to pass ftp commands as standard input to the ftp statement. Use a "here document" like in the following example:
Code:
ftp -ni host << EOF > /dev/null
user username password
ls
bye
EOF
Note that the closing EOF must be at the beginning of the line (no leading spaces or tabs) otherwise it is not interpreted from the shell and the standard input is not terminated. Also the user command let you avoid to interactively type username and password. A downside is that you have to write the password in clear text in a script and other people may read (and use) it.

Last edited by colucix; 05-26-2009 at 04:52 AM.
 
Old 05-26-2009, 08:32 AM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
may i suggest scp
 
Old 05-26-2009, 10:59 AM   #4
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Rep: Reputation: 49
Quote:
Originally Posted by schneidz View Post
may i suggest scp
For doing a simple `ls`, I think `ssh` may be more useful, but that's just my $0.02 -- there are many ways to arrive at the same goal!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script commands kushkothari Programming 3 10-20-2008 01:47 PM
commands in shell script ? wolfindark Linux - Newbie 5 07-07-2008 04:29 AM
help with shell script commands Andrew0 Linux - Newbie 1 04-15-2006 12:55 PM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 02:34 PM
Commands/Shell script ?? paraiso Linux - Newbie 11 04-21-2005 10:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration