Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
Hi, I am trying to write some shell scripts to automate a task. This is my first attempt at doing this. What I want to do is have 2 scripts, ...
  1. #1
    Just Joined!
    Join Date
    Apr 2008
    Location
    Chicago, IL
    Posts
    34

    Noob stuck writing FTP scripts

    Hi,

    I am trying to write some shell scripts to automate a task. This is my first attempt at doing this. What I want to do is have 2 scripts, the first script is to create a directory using the current date and copy the files from the ftp script.

    Here is my first script

    ftpstartup.sh
    #!/bin/sh
    Today="`date +%m%d`"
    mkdir /home/***checkout/$Today
    cp * /home/***checkout/$Today
    ftp < autoftp.sh

    and the next script is the ftp script autoftp.sh

    #!/bin/bash
    open 10.1.2.235
    username
    password
    cd /home/carsids/garyftp/***checkout
    get Patron.csv
    get GroupCRS.csv
    get GroupMemb.csv
    bye

    The problem is the ftp script, it doesn't recognize the username line or beyond.

    Does anyone have any advice as to where my mistake is?

    I am running CentOS 5.3.

  2. #2
    Linux Engineer Segfault's Avatar
    Join Date
    Jun 2008
    Location
    Acadiana
    Posts
    855
    Put authentication stuff in your .netrc file.

  3. #3
    Just Joined!
    Join Date
    Jul 2009
    Posts
    58
    I'm surprised it's accepting the hostname.

    I would think you need to do something like this:

    Code:
    foo=`autoftp.sh` 
    eval ftp -n ${foo}
    
    
    in the second script, everything has to be an "echo" 
    echo "quote USER $USER"
    echo "quote PASS $PASSWD"
    ...
    exit 0
    for it to even have a chance of working. I don't think it will though.

  4. #4
    Just Joined!
    Join Date
    Apr 2008
    Location
    Chicago, IL
    Posts
    34

    Still stuck, another SFN question

    I cannot locate the .netrc file anywhere in the file tree. What is the pathway?

    I do apologize for the dumb questions, but I have never written anything like this before.

  5. #5
    Linux Guru
    Join Date
    Nov 2007
    Posts
    1,695
    Google: bash ftp script => One of many links

  6. #6
    Linux Engineer Segfault's Avatar
    Join Date
    Jun 2008
    Location
    Acadiana
    Posts
    855
    You have to create .netrc file in your home directory.

    netrc(5): user config for ftp - Linux man page

    Other programs read this file too, e.g. wget.

  7. #7
    Just Joined!
    Join Date
    Apr 2008
    Location
    Chicago, IL
    Posts
    34
    Thank you to Segfault, HROAdmin26, and aram535. I still cannot get the username and password to populate using a script. I don't know how to do this, and all of your efforts have helped, but I don't have the skills to get it done.

    Can anyone point me in a specific direction as to how I can get this to work? I am frustrated and everything I have read is telling me something different and none of the solutions I have tried have come close to working.

    Performing a Google search of ftp bash script gives me information overload. Does anyone out there know of a book I can maybe find that can help?

  8. #8
    Linux Engineer Segfault's Avatar
    Join Date
    Jun 2008
    Location
    Acadiana
    Posts
    855
    Code:
    machine ftp.funet.fi
    login ftp
    password ftp
    This is the simplest .netrc file, make sure it has -rw------- permisssions. With this one can log into ftp.funet.fi without giving username and password. (Both username and password are ftp in this case.)

  9. #9
    Just Joined!
    Join Date
    Apr 2008
    Location
    Chicago, IL
    Posts
    34

    Just about ready to give up...

    thanks Segfault,

    that .netrc file worked, but it isn't working for the project I am stuck on.

    I need the login and password to be sent from the .netrc file to the ftp server, but it isn't working.

    I don't know what I'm doing and I can't find enough documentation to help me get there. Here is where I'm stuck.

    autoftp.sh
    Code:
    #!/bin/sh
    
    ftp 10.1.2.235
    username
    password
    cd /home/ca/gftp/wco
    get file1
    get file2
    get file 3
    bye
    for the .netrc I have

    Code:
    machine 10.1.2.235
    default login username password password
    login username
    password password
    I am sorry to keep bugging people about this, but I am clueless and I feel like I'm learning less than more as I struggle with this simple task.

    J (completely lost and confused noob)

  10. #10
    Super Moderator MikeTbob's Avatar
    Join Date
    Apr 2006
    Location
    Texas
    Posts
    7,144
    Hang in there buddy, you'll get it right. This isn't Schoolwork is it?
    I do not respond to private messages asking for Linux help, Please keep it on the forums only.
    All new users please read this.** Forum FAQS. ** Adopt an unanswered post.

Page 1 of 2 1 2 LastLast

Posting Permissions

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