Simple shell script to ftp put a file

I have the following script:

#!/bin/bash
filename="/home/paul/myfile.tar.gz"
hostname="ftp.myhost.com"
username="username"
password="password"
ftp -un $hostname <<EOF
quote USER $username
quote PASS $password
binary
put $filename
quit
EOF


But when run, with all the variables filled in, I get this:

ftp: Invalid URL `n'

What am I doing wrong?

Posted on Mar 12, 2011 9:13 PM

Reply
10 replies

Mar 12, 2011 9:59 PM in response to Jeffrey Ellis

Got that one as well 🙂

#!/bin/sh
HOST='ftp.server.com'
USER='user'
PASSWD='password'
REMOTE='"remote file"'
FILE='"local file"'
DIR='/usr/home/User/public_html/'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd $DIR
put $FILE $REMOTE
quit
END_SCRIPT
exit 0


In this example, I tried to upload from a mounted volume:

FILE='"Volumes/Backup HD/Applications/ReadMe.txt"'


Normally, ftp would accept this. But when run from the script, it balks:

Can't open `Volumes/Backup HD/Applications/ReadMe.txt': No such file or directory


So I guess the question again is, what am I doing wrong?

Mar 13, 2011 4:41 AM in response to Jeffrey Ellis

Not sure what the problem is, but curl might be easier:
<pre style="border: 1px solid #bbb; padding-left: .75ex; padding-top: .25em; padding-bottom: .25em; margin-top: .5em; margin-bottom: .5em; margin-left: 1ex; max-width: 100ex; overflow: auto; font-size: 10px; font-family: Monaco, 'Courier New', Courier, monospace; color: #333; background: #e6e6e6; line-height: normal">url -u user:password -T local/path/to/file ftp://example.com/remote/path/to/file</pre>

Message was edited by: Cole Tierney

Mar 13, 2011 6:16 AM in response to Jeffrey Ellis

Ah, can't use CURL. This for a script I'm writing for public consumption.


Um, eh? Why not? What do you mean by "public consumption" here? A desire to avoid adding dependencies and availability? You do realize that cURL is part of part of Mac OS X and Mac OS X Server? Some other consideration here?

(Given a choice, getting rid of ftp would make support easier. sftp, for instance, can make a chunk of this problem go away once the keys are established, including the embedded credentials. There are other options; I'm using stuff that does a remote afp mount, for instance. rsync direct, or via ssh. ftp is nasty, gnarly, insecure, fussy and largely incompatible with firewalls. But other than that, ftp is just slow.)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Simple shell script to ftp put a file

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.