Results 1 to 8 of 8

Thread: Bash Script for FTP login

  1. #1
    Join Date
    Aug 2006
    Beans
    1,225

    Bash Script for FTP login

    I would like a simple script to automate logging in to my FTP server, which requires authentication in clear text. I know, of course, how to launch a script that asks to open the ftp connection, but I don't know bash well enough to get it to supply the username and password. Of course, I can implement this in other languages, but I don't want to.

    Can anyone give me a lesson?

  2. #2
    Join Date
    Apr 2006
    Beans
    1,979
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: Bash Script for FTP login

    Does your ftp program support supplying the user and pass directly from the command line? If so, just use that. If you're unsure, just check out the man page and see what obscure nuggets of information are there.

  3. #3
    Join Date
    Aug 2006
    Beans
    1,225

    Re: Bash Script for FTP login

    Maybe I wasn't clear. Currently, I can open a terminal and type "ftp". That opens ftp in my terminal. Then I use open destination. That establishes a connection to my ftp server, which prompts me for my username. I just want a script that will do this for me, so I don't have to keep doing it manually. I don't to keep manually typing the same set of commands each time I need to connect.
    Last edited by phossal; February 13th, 2007 at 05:34 PM.

  4. #4
    Join Date
    Oct 2005
    Location
    IN, USA
    Beans
    274

    Re: Bash Script for FTP login

    You might check out scp .... it's more secure than ftp and will probably do more what you want.

    You can set up a cert so that you do not have to login to transfer files.

    Also, I have shell aliases set up, so that moving files around looks like this:

    Code:
    #copies file  somefile.txt  to a server set in variable $server1
    
    scp somefile.txt $server1:

  5. #5
    Join Date
    Sep 2006
    Beans
    2,914

    Re: Bash Script for FTP login

    Quote Originally Posted by phossal View Post
    Maybe I wasn't clear. Currently, I can open a terminal and type "ftp". That opens ftp in my terminal. Then I use open destination. That establishes a connection to my ftp server, which prompts me for my username. I just want a script that will do this for me, so I don't have to keep doing it manually. I don't to keep manually typing the same set of commands each time I need to connect.
    basic way of doing this
    Code:
    ftp -n -i <<_EOF_
    open hostname
    user username password
    bin
    cd "$DEST_DIR"
    lcd "$SRC_DIR"
    mget *
    quit
    _EOF_

  6. #6
    Join Date
    Mar 2006
    Beans
    199

    Re: Bash Script for FTP login

    use sftp. Then you can set up your keys to allow passwordless login via ssh and sftp. To log into your sftp session, it's as simple as
    Code:
    sftp user@host
    with no passwords.

  7. #7
    Join Date
    Jul 2005
    Location
    Remote Desert, USA
    Beans
    683

    Re: Bash Script for FTP login

    Do it with 'Expect' and hook it through 'Bash'.
    SuperMike
    When in doubt, follow the penguins.
    Evil Kitty is watching you

  8. #8
    Join Date
    Mar 2006
    Beans
    199

    Re: Bash Script for FTP login

    Here you go:
    Code:
    sudo apt-get install expect
    Then take this code:
    Code:
    #!/usr/bin/env expect
    
    set username yourUsername
    set pass yourPasswd
    set host theHost
    
    spawn ftp ${username}@${host}
    expect "Password:"
    send "${pass}\r"
    expect "ftp> "
    interact
    and put it into a file, say autoftp, then
    Code:
    chmod +x autoftp
    That should do what you want.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •