In article <st1jn9$poc$
[email protected]>,
Janis Papanagnou <
[email protected]> wrote:
I have a shell script like the one depicted below as excerpt to invoke
simple ftp-transfers; the script invokes expect, and expect spawns ftp.
That script has issues with (today common) pathological file names.
How would the correct quoting be done to pass the file with the below >depicted filename through all these nested tools?
server=...
file='A (pathological) file name w/ blanks, parenthesis, etc.pdf'
...
expect <<EOT
spawn ftp -i "${server}"
...
expect "ftp> "
send "put ${file}\r"
...
EOT
There are basically 3 ways to "script" FTP transfers:
1) Directly. By this, I mean by supplying the actual FTP commands on stdin and/or writing them to a file, then invoking FTP with some silly options to
get it to run in script mode. Most of the answers so far on this thread
have been in this category. I find this method hinky and try to avoid it
if at all possible.
2) Using Expect. This is the method I'm most comfortable with, and I
encourage you to stay with it. I would do it more like this, though:
#!/usr/bin/expect --
spawn ftp [lindex $argv 0]
...
expect "ftp> "
send "put [lindex $argv 1]\r"
...
Then I would call that script passing the server and the filename as
command line args. Note that in all my years of Expect scripting, I never figured out a way to access the command line args (In Expect/TCL-speak,
$argv) from a command line (-c 'Expect Script Here') Expect program. It
only seems to work when the script is in a file. I am open to suggestions about how to do that.
Note, BTW, that I *think* what you did originally would/should work if you
had used "-c" to pass the Expect script on the command line, rather than feeding the script in via stdin.
3) Using some other command line tool that is designed for automating FTP transfers. I've used ncftpget/ncftpput in the past; there are more
current versions of the general concept now, like "curl" and "iftp" and so
on. These all seem to work well, and I've nothing bad to say about them.
Finally, note that the oft-given-advice at this point is to not use FTP
since it is "insecure". The kewl people nowadays all use ssh/scp or some variant thereof. Any particular reason you aren't doing that too? Any
reason you don't want all your friends to think you're kewl?
--
Faced with the choice between changing one's mind and proving that there is
no need to do so, almost everyone gets busy on the proof.
- John Kenneth Galbraith -
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)