Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, this is my first post. I'm trying to write a simple script to upload multiple files to my incoming directory on my work's ftp server. I think I've got ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! Eric_the_Red's Avatar
    Join Date
    Feb 2006
    Posts
    3

    Question Having trouble with simple batch ftp script (bash)


    Hi, this is my first post. I'm trying to write a simple script to upload multiple files to my incoming directory on my work's ftp server. I think I've got most of it correct, as I've transferred individual files with the script. I tried to use a while loop to iterate through each positional parameter on the command line that corresponds to a file to be transferred:

    Code:
    #! /bin/sh
    
    SCRIPT=`basename $0`
    
    if [ -z "$1" ] ; then
      echo "$SCRIPT: Usage: `basename $0` File-one File-two File-three"
      exit 1
    fi  
    
    SERVER=server_name_goes_here
    DIRECTORY=incoming_directory_goes_here
    
    PASSWORD="my_email_address"
    echo -e "\nBeginning ftp transfer...\n"
    
    while [ -n "$1" ] ; do
    	FILENAME=`basename $1`
    	ftp -n $SERVER <<End-of-Session
    	user anonymous "$PASSWORD"
    	binary
    	bell
    	cd $DIRECTORY
    	pwd
    	put "$FILENAME"
    	ls
    	bye
    	End-of-Session
    	shift
    done
    
    echo -e "\nftp session ended..."
    
    exit 0
    However, upon executing this script, I get the error message:
    "ftp.sh: line 35: syntax error: unexpected end of file"

    Is my shift command misplaced, perhaps?

    Thanks,

    ~ Eric

  2. #2
    Just Joined!
    Join Date
    Mar 2006
    Posts
    34
    The only problem I see is that your second "End-Of-Session" should be at the start of its line, with no leading whitespace (at least, going by the behavior of my system's GNU bash 3.0). However, I'm not sure how you got this to work for single-file transfers...

Posting Permissions

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