LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-09-2010, 07:11 PM   #1
stancol
LQ Newbie
 
Registered: Nov 2004
Location: Grand Island, NE
Distribution: SME 6.0,Red Hat 7.3,Debian
Posts: 4

Rep: Reputation: 0
ncftpput with spaces in file names


Tried searching for this but had no luck. So if I missed the answer to my question please post a link. Hopefully I'm posting in the right area as this is my first post to this forum.

Wrote me a nice script to upload only new files recursively from a directory. Only problem I'm having is when it comes to files with spaces in the name.

According to the ncftp manual:

ncftpput [options] remote-host remote-directory local-files...

Where I run into trouble is the s on the end of local-files. Since you can put more than one file in the upload string the spaces in files simply look like seperate files and the upload fails.

-----Script goes kind of like this-----

upload=`find $local -newer $status -type f`

touch $status

if [ -z "$upload" ]; then
echo "Nothing to do...exiting"
exit
else
#SAVEIFS=$IFS
#IFS=$(echo -en "\n\b")
for each in $upload; do
remote_dir=`echo "$each" | awk -F/ '{ print $6 }'`
echo -en "\n\nRemote Directory=$remote_dir"
echo -e "File Name=$each"
cmd1="$ftp -b -u $username -p $passwd $host /$remote_dir ${each}"
$cmd1
#IFS=$SAVEIFS
done
fi
exit

-----End Script-----

I've tried it with and without the $IFS line and it still fails. Any ideas on how to make to do an upload with files that contain spaces?

(Might have to break down and try something other than ncftpput but it works so well except for the space issue.)
 
Old 03-09-2010, 07:26 PM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
Put quotes in the output around the file name ?

Code:
cmd1="$ftp -b -u $username -p $passwd $host /$remote_dir "${each}""
Might need to experiment with type of quote a bit. It may not like set of double quotes inside double quotes.

Don't know enough bash to know which ones are important, but in perl you can use single quotes surrounding the command and double quotes inside. Or vice versa. You may even need to escape them.

Last edited by smoker; 03-09-2010 at 07:28 PM.
 
Old 03-09-2010, 11:53 PM   #3
stancol
LQ Newbie
 
Registered: Nov 2004
Location: Grand Island, NE
Distribution: SME 6.0,Red Hat 7.3,Debian
Posts: 4

Original Poster
Rep: Reputation: 0
Been there done that

Quote:
"${each}"
Tried it....no luck.

Also tried '${each}' with no luck. I hope your right and I just need to figure out how to quote it correctly.
 
Old 03-10-2010, 11:32 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

Not really sure why your script doesn't work. But if you try something else, try lftp. It has a command called mirror that does exactly what the script does. So you could do it with a single lftp command instead.
 
Old 03-10-2010, 12:07 PM   #5
stancol
LQ Newbie
 
Registered: Nov 2004
Location: Grand Island, NE
Distribution: SME 6.0,Red Hat 7.3,Debian
Posts: 4

Original Poster
Rep: Reputation: 0
Well this works

Found an answer to my script issue:

Code:
upload=`find $local -newer $status -type f`

touch $status

if [ -z "$upload" ]; then
    echo "Nothing to do...exiting"
    exit
        else
            SAVEIFS=$IFS
            IFS=$(echo -en "\n\b")
            for each in $upload; do
            remote_dir=`echo "$each" | awk -F/ '{ print $6 }'`
            echo -en "\n\nRemote Directory=$remote_dir"
            echo -e "File Name=$each"
            ncftpput -bb -u $username -p $passwd $host /$remote_dir "$each"
            IFS=$SAVEIFS
            done
            fi
exit
By getting rid of the cmd1= part and replacing it directly with ncftput I didn't need the double quotes so I could then effectively use them around $each.

I'm trying to recursively upload only files that have changed in a directory. No changes = no upload. The thing I like about ncftpput is that you can set it up into a batch file. Then you can choose when you want to execute the upload via the command 'ncftpbatch'.

Haven't tried the lftp command but it looks like it has some cool applications as well. I'll have to explore that later now that I have a working script.

Thanks for all the useful input.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to handle file names with spaces in them bahadur Programming 14 04-04-2005 12:04 PM
how to handle file names with spaces in them bahadur Programming 3 03-23-2005 05:15 AM
du or wc and file names with spaces bramadams Slackware 2 01-27-2005 11:43 AM
Spaces in file names JohnKFT Slackware 3 11-09-2004 03:44 PM
File/Direcory Names with Spaces ar1 Linux - General 3 01-15-2004 10:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration