Your best friend for file transfer.

Fetch application logoFetch

AppleScripting a download (8 posts)

This is an archived topic. The information in it is likely to be out-of-date and no longer applicable to current versions of Fetch.
  • Started 20 years ago by Jaharmi
  • Latest reply 20 years ago from Jaharmi
  • Jaharmi Member

    I'm trying to AppleScript an authenticated download. I want to download a specific file from a specific URL, avoiding a file listing of the parent directory if at all possible (it's huge). I'm having some problems.

    The transcript reports:

    220 ftp.xxx.yyy ready.
    USER anonymous
    331 Anonymous login ok, send your complete e-mail address as password.
    PASS
    230 Anonymous access granted, restrictions apply.
    SYST
    215 UNIX Type: L8
    PWD
    257 "/" is current directory.
    MACB ENABLE
    500 MACB not understood.
    CWD usr/var/spool/mail/jeremy
    550 usr/var/spool/mail/jeremy: No such file or directory
    ftp_cwd: -30006 (state == CHANGING_DIR)

    First of all, it's logging in anonymously, and I'm not sure how to best avoid that. I'd like Fetch to prompt the user for a userid/password combination; I'd rather not try to encode it in the URL.

    Second of all, it's having problems going to the correct directory. Note that the last item in the path I'm requesting is a file, not a directory. I suspect Fetch is trying to change to the directory of "jeremy," which won't work. I suspect that it's also having a problem because one or more of the directories down the path requires an authenticated user ...

    Is there a way to specify a direct file path for a single downloaded file, and also enable authentication? Is there one method that's better than another?

    Thanks!

    --
    Jeremy

    [This message has been edited by Jaharmi (edited 10-21-2003).]

    [This message has been edited by Jaharmi (edited 10-21-2003).]

    [This message has been edited by Jaharmi (edited 10-21-2003).]

    Posted 20 years ago #

  • Jaharmi Member

    If I try this construction:

    tell application "Fetch 4.0.3"
    activate
    make new transfer window at beginning with properties {hostname:"ftp.xxx.yyy", userid:"jeremy", initial directory:"/"}
    end tell

    ... then I can specify a username but not a password. I'd prefer not to prompt my users for a password, displayed in a plain-text AppleScript dialog.

    [This message has been edited by Jaharmi (edited 10-21-2003).]

    [This message has been edited by Jaharmi (edited 10-21-2003).]

    Posted 20 years ago #

  • Jaharmi Member

    [QUOTE]Originally posted by Jaharmi:
    [B]If I try this construction:

    tell application "Fetch 4.0.3"
    activate
    make new transfer window at beginning
    with properties {hostname:"ftp.xxx.yyy", userid:"jeremy", initial directory:"/"}
    end tell

    ... then I can specify a username but not a password. I'd prefer not to prompt my users for a password, displayed in a plain-text AppleScript dialog.

    --
    Jeremy

    Posted 20 years ago #

  • Jim Matthews Administrator

    Here's a script that works for me (with the hostname and file path changed):

    set dialog_result to display dialog "Please enter your FTP User ID:" default answer "userid"
    set entered_userid to text returned of dialog_result
    set url_to_download to "ftp://" & entered_userid & ":@ftp.xxx.yyy/dir/filename.gif"

    tell application "Fetch 4.0.3"
    duplicate url url_to_download to beginning of alias "HD:Users:matthews :Desktop:"
    end tell

    Fetch will prompt for the password, if it isn't in the keychain.

    Fetch will list the directory after doing the download; I can't think of a way to get around that.

    Thanks,

    Jim Matthews
    Fetch Softworks

    [This message has been edited by JimMatthews (edited 10-21-2003).]

    Posted 20 years ago #

  • Jaharmi Member

    The "duplicate" command seems to be working for me. The file listing at the end takes a while, but if I wrap it in a timeout, then I can get rid of it rather than wait for it to list the directory contents.

    --
    Jeremy

    [This message has been edited by Jaharmi (edited 10-21-2003).]

    Posted 20 years ago #

  • Jaharmi Member

    Thanks, Jim. You put me on the right track. I know have something that works passably well.

    If I can provide some feedback, it seems to me that there are many downloading commands in the dictionary, and it's not terribly obvious how they work. It might be helpful to include a couple of example scripts that demonstrate the use of each command, and what its options are. (I never would have hit upon "duplicate" as I was too busy trying "download" and other commands that *sounded* right.)

    Also, is there a way to just bring up a transfer window, pointing a specific spot, using authentication? At the end of my script, I want to leave a transfer window open at a specific directory, for a file listing and further transfers.

    Thanks!

    --
    Jeremy

    Posted 20 years ago #

  • Jim Matthews Administrator

    There are some example scripts in the "Fetch Example Scripts" folder, and some in the AppleScript topic in Fetch Help, but I agree that more examples would be better.

    duplicate is the command to use if you want to copy the file to a specific destination folder (akin to dragging and dropping). download is equivalent to double-clicking a file or clicking the Get File button -- it puts the file in the default download folder.

    To have Fetch open a transfer window for a certain directory I'd say:

    open url "ftp://userid:@hostname/path"

    The user will be prompted for a password (or you can put one between the colon and at-sign).

    Thanks,

    Jim Matthews
    Fetch Softworks

    Posted 20 years ago #

  • Jaharmi Member

    I had not looked at the Fetch help for examples. In my copy of Fetch 4.03, I had not found any download examples using any commands -- mostly scripts to set various hidden preferences and do uploads.

    Posted 20 years ago #

Topic closed

This topic has been closed.