LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Auto FTP login, without .netrc, reconnect stdin (https://www.linuxquestions.org/questions/linux-general-1/auto-ftp-login-without-netrc-reconnect-stdin-746420/)

rhlee 08-10-2009 07:54 AM

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:

Code:

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

Code:

ftp -vn host.com << EOF
user usr pass
EOF

But both commands close immediately.

Code:

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 http://www.linuxforums.org/forum/lin...n-problem.html

In that post, he closes the stdin using

Code:

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

Code:

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

So it would evaluate to

Code:

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>"


Cheers,

Richard


All times are GMT -5. The time now is 11:49 AM.