Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to set up an alias that connects to an ftp site..

so far (with the help of SO :] ) I've been able to create the alias that will connect.

I've tried adding the next command preceded by a semi-colon but it doesn't work.

What I'm looking for is a way to do:

ftp -p domain.com
[wait until the server asks for username]
my_username
[wait until server asks for p/w]
password123

etc...

is this possible in one alias? if so, what is this called so I can learn how to do it?

Thanks!

share|improve this question

migrated from stackoverflow.com Sep 13 '12 at 23:58

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers

up vote 2 down vote accepted

Actually, I don't think you'll be able to have the alias help you once you are connected. You can do some more at the command line when you log in, check the ftp man page, but I think you can specify your username with the -u option (ie. ftp somesite.edu -u my_username).

Once ftp starts prompting you for info (like your password) you are on your own.

A number of years ago, there was a tool called "expect" that could be used to script such interactive sessions, but there might be other (better?) ways to do this.

Update 1 .. can't find the -u option in the on line man pages ... I could have sworn this was available. Still a tool like expect should be able to help.

Update 2: have you considered using sftp instead? If you set it up correctly, you won't need to supply the password, and you can specify the user in the command line, e.g.,

  sftp  username@somesite.edu

also, scp will let you copy files to/from other sites, again with the username specified and passoword not needed if properly set up before.

share|improve this answer
    
Thanks, Yea I noticed nothing I do has an effect on the command line once I'm connected. I'm trying to write a pretty complex command in an alias to interact with my server, but the -u is helpful too! –  d-_-b Sep 12 '12 at 23:57
    
@iight I must have gotten the -u confused from some other command, sorry. –  Levon Sep 13 '12 at 0:02
    
If i'm not mistaken it reminds me of a mysql command line... –  d-_-b Sep 13 '12 at 0:02
1  
@iight yes, could very well be .. I had to double check to make sure it's not there. In any case, if you have the option between sftp and ftp, the secure version would be preferable. I added links to my answer –  Levon Sep 13 '12 at 0:04
    
Thanks this is very helpful! –  d-_-b Sep 13 '12 at 0:07
add comment

Have you tried:

alias doit='echo my_username > tmpfile ; echo password123 >> tmpfile ; ftp -p domain.com < tmpfile'
share|improve this answer
    
Sorry this didn't work, it seems to freeze the terminal...perhaps I'm writing it wrong though –  d-_-b Sep 13 '12 at 0:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.