Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 08-10-2009, 08:54 AM   #1
LQ Newbie
Registered: Aug 2009
Posts: 11

Rep: Reputation: 0
Auto FTP login, without .netrc, reconnect stdin

Dear Linux Qs,

My question is a variation on the automatic ftp login question.

I know I can use .netrc to store ftp credentials and macros. But the problem is that the ftp credentials can change regularly.

I'm trying to write a simple script (or even better a one liner) that will automatically log into ftp for me but will give me back control after the login rather than just closing the ftp connection.

I can login using an echo pipe:

echo user usr pass | ftp -vn
Or using a here document:

ftp -vn << EOF
user usr pass
But both commands close immediately.

220 FTP server ready.
331 Please specify the password.
230 Login successful.
221 Goodbye.
Is there a way to reconnect the stdin back to the keyboard?

If found a post

In that post, he closes the stdin using

exec 0<&-
He then reconnects it to they console using

term="/dev/$(ps -p$$ --no-heading | awk '{print $2}')"
exec < $term
So it would evaluate to

exec < /dev/tty
or something.

But I don't know implment this into a script.

Also, out of ineterest, why when I pipe input, I don't see the input prompt? i.e. the "ftp>"



Last edited by rhlee; 08-10-2009 at 10:53 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
ftp and .netrc Canis Polaris Linux - Newbie 3 11-25-2008 05:34 PM
ftp in inittab -.netrc issue svar Linux - Networking 11 10-10-2007 03:15 AM
trouble logging in to ftp with .netrc laclac01 Linux - General 1 10-27-2005 02:15 PM
How to auto login into ftp mphreddy Programming 2 10-29-2003 07:30 AM
How to set anscii mode in FTP using .netrc gendreau Linux - Newbie 1 08-08-2003 01:05 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:30 PM.

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