• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Scripting Terminal for simple FTP
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scripting Terminal for simple FTP


  • Subject: Re: Scripting Terminal for simple FTP
  • From: Deivy Petrescu <email@hidden>
  • Date: Sat, 5 Apr 2003 20:00:57 -0500

On Thursday, April 3, 2003, at 02:27 PM, Andrew Oliver wrote:

> 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
> :)

Andrew,
would you accept instead of downloading the newest version of a list
of file on the server
deleting the oldest version of a list of files on the server ?
I believe you can see is the same.
I have such script. You can make the changes you want and delete or
download as many files as you want.
Tested!

<script>

set theScript to "ftp -n [machine]
user [username] [password]
cd [your directory here]
ls -tr
bye"


tell application "Terminal"
do script theScript in window 1
delay 2
set zt to contents of window 1 as string
set zdelte to my cutfile(zt, ".html")
display dialog "I will erase the file " & text item -1 of zdelte &
return & "Crated on " & (text items -5 thru -2 of zdelte as string)
if button returned of result is {"OK"} then do script my filecut(text
item -1 of zdelte) in window 1
end tell


to cutfile(atext, aword)
set lis to {}
set li to (every paragraph of atext)
repeat with l in li
if (l as string) contains aword then
log {"li", (l as string)}
set end of lis to (l as string)
end if
end repeat
set text item delimiters to " "
set zfil to text items -5 thru -1 of item 1 of lis
return zfil
end cutfile

to filecut(afile)
return "ftp -n [machine]
user [username] [password]
cd [your directory here]
delete " & afile & "
bye"
end filecut

</script>
_______________________________________________
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.

References: 
 >Re: Scripting Terminal for simple FTP (From: Andrew Oliver <email@hidden>)

  • Prev by Date: Re: Space in POSIX path/Terminal shell
  • Next by Date: Re: Eudora in the stone age? (was IF Syntax)
  • Previous by thread: Re: Scripting Terminal for simple FTP
  • Next by thread: Re: Scripting Terminal for simple FTP
  • Index(es):
    • Date
    • Thread