Re: Scripting Terminal for simple FTP
Re: Scripting Terminal for simple FTP
- Subject: Re: Scripting Terminal for simple FTP
- From: Andrew Oliver <email@hidden>
- Date: Thu, 03 Apr 2003 11:27:21 -0800
On 4/3/03 10:19 AM, "Paul Skinner" <email@hidden> wrote:
>
You can certainly achieve this type of interaction through the 'do
>
shell script' command. It really makes no difference if you're in the
>
shell looking at the results or in a choose from list dialog. You can
>
code whatever interactive options you want.
OK then, Paul.
Please show me how to use 'do script' in the Terminal to download via ftp
the last-named file of a sequentially-named series of files from a specified
directory.
For example, the /pub/files/ directory on the ftp server ftp.mydomain.com
contains a number of files: file01.txt file02.txt and file03.txt as well as
an unspecified number of other files.
I want an AppleScript to use the terminal to login to the server using a
specified username/password and download only the latest filexx.txt file
which right now may be file03.txt, but tomorrow might be file04.txt
I want the script to automatically decide which file to download, although
I'll accept, at a pinch, displaying a list of filexx.txt files for the user
to choose from (although, if you can get that listing the logic to choose
the file is simple).
I maintain this can not be done because you can not retrieve the results of
the previous 'do script' action. You can 'do script "ftp ftp.mydomain.com",
but you cannot interactively log in, or get the directory listing (unless
you want to repeatedly 'get contents of window 1" to read the entire
terminal screen, which may not work with long file listings). You cannot,
therefore see what files are available for download or make the decision as
to which file to download.
You can do this using 'do shell script' (not in a 'tell application
"Terminal" block), because do shell script returns the stdout of the shell
command to AppleScript, and you can react to that. 'do script' in the
Terminal does not.
Andrew
:)
>
>
On Thursday, April 3, 2003, at 11:28 AM, Andrew Oliver wrote:
>
>
> I'm sorry but the examples below are *still* not examples of
>
> *interacting*
>
> with the ftp terminal session in progress, they are just variations on
>
> a
>
> theme of how to string multiple inputs together.
>
>
>
> Proper interaction requires the ability to make decisions based on the
>
> results of an earlier action.
>
>
>
> For what it's worth, if you're just trying to minimize the number of
>
> lines
>
> to download a file using ftp, you can't beat:
>
>
>
> do shell script "ftp ftp://user:email@hidden/path/to/file"
>
>
>
> Prepend the shell script with 'cd /path;' to download the file to a
>
> specific
>
> directory instead of the current directory.
>
>
>
> IMHO, the closest I've seen to an scripted interactive ftp session is
>
> multiple curl commands strung together, essentially initiating
>
> separate ftp
>
> connections for each step.
>
>
>
> Then, of course, there's always .netrc
>
>
>
> Andrew
>
> :)
>
>
>
> On 4/3/03 6:52 AM, "Nigel Smith" <email@hidden> wrote:
>
>
>
>> On 3/4/03 15:21, "Chris Janton" <email@hidden> wrote:
>
>>
>
>>> On Tuesday, April 1, 2003, at 11:00 PM,
>
>>> email@hidden wrote:
>
>>>
>
>>>> In this specific case, the question related to controlling the ftp
>
>>>> connection, and that can't be done, even with semi colon-separated
>
>>>> commands
>
>>>> passed in the 'do shell script'.
>
>>>
>
>>>
>
>>> tell application "Terminal"
>
>>> set myIndex to (get the index of every window whose name is "my test
>
>>> window")
>
>>> do script "ftp foo.com" in window myIndex
>
>>> do script "user bar" in window myIndex
>
>>> do script "xyzzy" in window myIndex -- this is the password
>
>>> do script "ls P*" in window myIndex
>
>>> do script "exit" in window myIndex
>
>>> end tell
>
>>
>
>> Way too many do scripts for my poor brain to handle :-)
>
>>
>
>> How's about (for example):
>
>>
>
>> set theScript to "ftp -n [machine-name]
>
>> user [username] [password]
>
>> cd /var/www/htdocs/nigel_test
>
>> ls
>
>> lcd ~/Desktop
>
>> bin
>
>> get vars_ssi_test.shtml"
>
>>
>
>> tell application "Terminal"
>
>> do script theScript
>
>> end tell
>
>>
>
>> Works over here on OSX 10.2.4, though you'll want to change the ftp
>
>> commands
>
>> to do your own thing...
>
>>
>
>> Nigel
>
_______________________________________________
>
applescript-users mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/applescript-users
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.