I am running this from PHP, using escapeshellarg for each argument, but I can't get it working in shell or PHP. One thing to note is my passwords contain !. and all sorts.
Replace all single quotes with double quotes. Single quotes prevent variable expansion in a shell-script, so $1, $2,... will be passed literally to echo and ncftpput
Brilliant, thanks, it is running the command properly now, but ncftpput is erroring because of the username/password. I think this is because the password has .! in it, unfortunately I can't change this... any ideas?
Erm, sorry I'm unexperienced with shell scripting. I thought that would evaluate it, then the single quotes remained to make sure the password was accepted and didn't escape the command...
Therefore, shell doesn't actually do what you think it does.
Putting variables in double-quotes is a good idea when you don't want them to split. Single quotes don't evaluate variables at all. And extra quotes inside double quotes don't get evaluated, just stick around.
This however, doesn't, with the * to denote the contents of the folder, not the folder itself, it complains about not being able to change to a directory, and the "directory" it lists, is the first file in that folder... how do I use *?
Thanks in advance.
---------- Post updated 08-10-12 at 06:49 AM ---------- Previous update was 08-09-12 at 07:19 AM ----------
Sorry to bump, but I'm still having troubles with this script...could anybody point me in the right direction?
Sorry, I don't fully understand that. I know I'm coming across as wanting to be spoonfed
What do you mean by the shell will expand into more than $4? how do you 'shift off'? I understand $@ is all arguments separated with a space, but I am still unclear as to the rest.
It means you could also end up with $5, $6, $7, ... depending on how many files * finds. You're not putting a literal * into ncftp, and if you did, it probably wouldn't work. It's the shell's job to turn * into filenames for you ahead of time.
You shift with the shift command. It works like this:
set -- a b c d e # Set $1=a, $2=b, $3=c, ... for example
echo $1 # Should print a
shift 2 # Get rid of the first two
echo $1 # should print c
echo $2 # should print d
echo $3 # should print e
echo "$@" # should print c d e
"$@", quotes and all, is a special operator which means "all arguments". So if you get rid of the first few arguments, you can feed "$@" into your FTP program and feed it all the arguments instead of hardcoding $1 $2 $3 $4 etc.