Argument Problems with ncftpput


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Argument Problems with ncftpput
# 1  
Old 08-08-2012
Argument Problems with ncftpput

Hi there,

I'm having a problem with a shell script designed to FTP a folder across to a new server. I would appreciate any advice on how to get this working.

My current script is:
Code:
#/bin/bash
#

HOST=$1
USER=$2
PASS=$3
LOCALDIR=$4
REMOTEDIR=$5
echo "Running command: ncftpput -R -u '$2' -p '$3' '$1' '$5' '$4'"
ncftpput -R -u '$2' -p '$3' '$1' '$5' '$4'

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.

I appreciate any help in advance.

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.

Last edited by vbe; 08-08-2012 at 05:06 AM..
# 2  
Old 08-08-2012
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
# 3  
Old 08-08-2012
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?
# 4  
Old 08-08-2012
I don't think that .! would cause a problem. What is the exact error message?
# 5  
Old 08-08-2012
Quote:
Originally Posted by hergp
I don't think that .! would cause a problem. What is the exact error message?
Basically I've got a bit further:

I now have
Code:
#/bin/bash

echo "Running command: ncftpput -R -u "$2" -p '"$3"' "$1" "$5" "$4""
ncftpput -R -u "$2" -p '"$3"' "$1" "$5" "$4"

When I run it like this:
Code:
[root@mail httpdocs]# ./ftpWebsite.sh '123.456.789.012' 'username.co.uk' 'pass.!.!.!' '/var/www/vhosts/username.co.uk/httpdocs/*' '/public_html'

It then errors this:
Code:
ncftpput: cannot open 12.4.4.2: username and/or password was not accepted for login.

BUT: When I run the command that is printed (identical) straight from the command line, it works!?!

Said command is:
Code:
ncftpput -R -u username.co.uk -p 'pass!.!.' 123.1.1.1 /public_html /var/www/vhosts/username.co.uk/httpdocs/*

# 6  
Old 08-08-2012
Does it really read '"$3"' ? Do you think it should have both sets of quotes? If so, why?
# 7  
Old 08-08-2012
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...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Error:--test: argument expected--Even though i give an argument.

Hi All, I am running the script VBoxManage list vms |sed 's/"//g' | cut -d " " -f1 > har1out.mytxt result=`cat har1out.mytxt | grep $1' echo $result echo $1 { if then echo pass else echo fail fi (2 Replies)
Discussion started by: harsha85
2 Replies

2. Shell Programming and Scripting

Make script that run with argument if not run from configuration file argument

Hello, Is there any method thorugh which script can take argument if pass otherwise if argument doesn't pass then it takes the argument from the configuration file i.e I am workiing on a script which will run through crontab and the script will chekout the code ,zip and copy to the... (3 Replies)
Discussion started by: rohit22hamirpur
3 Replies

3. UNIX for Dummies Questions & Answers

Argument in Linux

I am trying to see the commands that can work also with only one argument. I tried that man to see the commands details but could not figure out. Here in my scenario I have ln, cp and mv commands. I am trying to see if these command can also work with just one argument. It looks like cp works if I... (3 Replies)
Discussion started by: linux17
3 Replies

4. Shell Programming and Scripting

argument

Im sorry but I'm in need of help. How would I give the user the option to include the name of an html file as an arugment for the script? but if none is provided, then the script should prompt the user for the file name. I have sed 's/<*>//g' yourfile.html | uniq >newfile.txt so far I have... (7 Replies)
Discussion started by: clicstic
7 Replies

5. Shell Programming and Scripting

Cannot compare argument in if statement in csh/grep command if argument starts with “-“

If ($argv == “-debug”) then Echo “in loop” Endif But this is not working. If I modify this code and remove “-“, then it works. Similarly I am getting problem using grep command also Grep “-debug” Filename Can someone please help me on how to resolve these... (1 Reply)
Discussion started by: sarbjit
1 Replies

6. Shell Programming and Scripting

get positive number n as argument script must calculate the factorial of its argument

Can someone please help me with this SHELL script? I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1. Here is a start but I have no clue how to... (3 Replies)
Discussion started by: I-1
3 Replies

7. Shell Programming and Scripting

Strict Argument

Im trying to write a bash script that has an if statment that when the user enters ONLY that exact argument, will echo what follows that conditon. For example: for file in $1 do if then Var1=$(cat hello | egrep "that pattern" | awk '{ print $NF }') cat $Var1 fi done Basically,... (3 Replies)
Discussion started by: oxoxo
3 Replies

8. UNIX for Dummies Questions & Answers

How to find the last argument in a argument line?

How to find the last argument in a argument line? (4 Replies)
Discussion started by: nehagupta2008
4 Replies

9. Shell Programming and Scripting

argument help

if i have 2 arguments $1 and $2 how can i append them so that $2 is added to $1? It is really confusing me because it seems so simple, yet i can't get the shell script to work properly. Thanks. (2 Replies)
Discussion started by: brentdeback
2 Replies

10. UNIX for Advanced & Expert Users

'make' problems (compliation problems?)

I'm trying to compile and install both most recent version of 'make' and the most recent version of 'openssh' on my Sparc20. I've run into the following problems... and I don't know what they mean. Can someone please help me resolve these issues? I'm using the 'make' version that was... (5 Replies)
Discussion started by: xyyz
5 Replies
Login or Register to Ask a Question