Applscript, CURL and parsing spaces

Hi Guys,
I have been going round and round on this for 3 days trying to figure out a way to do this. Basically, I am handing AS a text file that has a list of files to be downloaded from an FTP site.

I use a unique to find out which I have already downloaded and then once I know the ones I need to download, I begin the repeat cycle to download each file. The issue I run into is:

I run the spaces through a Text Item Delimiter to change the to "\ ". Because terminal translates spaces as "\ " and this character is an ignoring character in AS, it gives me strange results. I then thought, I would just ignore with an ignore "\ ". This however adds double \ in my output.

You can see in line 11 the log looks write, however when I take this filename and pass it to my shell script, the error is on 16. It has "\ " instead of "\ " any thoughts?

1"tell current application
2 do shell script “curl ‘ftp://website.org/Spot/’ --user ‘user:pass’ --list-only > ~/ftpNew.txt”
3 → “”
4 do shell script “sort ~/ftpOld.txt ~/ftpNew.txt | uniq -u”
5 → “Test A File With Spaces.rtf”
6 (Test A File With Spaces.rtf)
7 (1)
8 (Test A File With Spaces.rtf)
9 (‘/Test A File With Spaces.rtf’)
10 (T, e, s, t, \ , A, \ , F, i, l, e, \ , W, i, t, h, \ , S, p, a, c, e, s, ., r, t, f)
11 (FinalName is Test\ A\ File\ With\ Spaces.rtf)
12 open for access file “~/FileForUpload.txt” with write permission
13 → 161
14 write “Test\ A\ File\ With\ Spaces.rtf” to 161 starting at eof
15 close access 161
16 do shell script “curl ‘ftp://website.org/Spot/Test\\ A\ File\ With\ Spaces.rtf’ --user ‘user:pass’ -o ~/Desktop/Test\ A\ File\ With\ Spaces.rtf”
17 → error " % Total % Received % Xferd Average Speed Time Time Time Current
18 Dload Upload Total Spent Left Speed
19
20 0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
21 curl: (78) RETR response: 550" number 78
22 Result:
23 error " % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
curl: (78) RETR response: 550" number 78

If you’re concerned about spaces in the file name, just enclose the whole file name in single quotes:

‘This is my file.txt’

Hi Adam,
Thank you for your reply. Probably, I wasn’t as clear as I could be, but basically, I will show the output I would like, and what I am getting.

1. This output is of the script if I just have spaces in the filename.

tell current application
do shell script “curl ftp://website.org/Spot/A file with spaces.txt --user ‘user:pass’ -o ~/Desktop/Testing file.txt”

2. What the shell script needs is:

tell current application
do shell script “curl ftp://website.org/Spot/A\ file\ with\ spaces.txt --user ‘user:pass’ -o ~/Desktop/Testing file.txt”

3. if I use text Item delimiters to put these in, my output looks like this:

tell current application
do shell script “curl ftp://website.org/Spot/A\\ file\ with\ spaces.txt --user ‘user:pass’ -o ~/Desktop/Testing file.txt”’

How can I get #2 as my output? Thank you so much. This has been killing me.

I literally have this ‘function’ in a script open in the background right now.


on safeMod(input)
	set output to ""
	repeat with char in every character in input
		if char is in {" ", "\"", "\\", "(", ")", "{", "}", "[", "]"} then
			set output to output & "\\"
		end if
		set output to output & char
	end repeat
	return output
end safeMod

string in, string out. The output to the terminal should include "\ " instead of each space even if AS will see "\ " escaping the escape char. Try it.