Your best friend for file transfer.

Fetch application logoFetch

set current folder Applescript questions (6 posts)

  • Started 9 years ago by Jim Brandt
  • Latest reply 9 years ago from Jim Matthews
  • Jim Brandt Member

    Jim,

    I have a rather extensive script that delivers commercials to TV stations. Much of the work is being done by Fetch as most of the stations allow for FTP uploads of files.

    I have come across a need to change directories at a station to upload two different files to them. Each file has to go into a different directory.

    Because this system is parameter driven, I'm trying to make it as generic as possible at the individual file upload level. What I have encountered now though is something I need some help on.

    I have provided the script with essentially five parameters:
    1) the URL to connect to
    2) the user
    3) the password
    4) the directory ( or a list of directories if there are more that one)
    5) the file path of the file to upload (or list of file paths, if more than one)

    When I log in, I'm storing some basic variables (current folder, initial folder). However, when I first log in, initial folder returns an empty string and current folder returns "/".

    For the first file to upload, I determine the directory to put it in, change directories if necessary, upload the file, set the directory back to the parent folder (again if necessary) and repeat for all files in the list (it's generally only two when it's more than a single file, though the script should be able to handle more than two, if necessary).

    For the first time since I have implemented this system, one of the directories I need to connect to is two levels deep. Currently, the way I change directories is to issue the command:
    tell transfer window 1 to set current folder to UploadDir

    where UploadDir is a string containing the name of the directory on the remote server that I want to connect to.

    I can then get back to the login directory by issuing a command:
    tell transfer window 1 to set current folder to parent folder

    If it contains "Dir1" (and folder Dir1exists) then all is well. However, if UploadDIr contains "Dir1/Dir2" where Dir2 is a folder within folder Dir1, it fails with a -30006 error "Fetch could not open the folder “Dir1/Dir2” because the FTP server says that the requested item could not be accessed. (If you entered a file or folder name or URL, check that it is correct.)

    Does this mean that I have to parse my directory string and do multiple "set current folder to" commands to get to the final folder? And once I do, how do I unwind this to get back to the initial folder, since the command "tell transfer window 1 to set X to initial folder" ALWAYS comes back as an empty string? Does that mean I have to issue multiple "set current folder to parent folder" commands, remembering how deep in the folder structure I went?

    Why does the initial folder value always come back as an empty string? Am I missing something?

    TIA,

    Jim Brandt

    Posted 9 years ago #

  • Jim Matthews Administrator

    Hi,

    The initial folder is the folder that was specified by you when the transfer window was first opened. So if you don't specify an initial folder, that property will come back empty.

    I think you might want to actually use the "home folder" property. That is the folder path where the server puts you when you login (aka the login directory). For example, you could do something like:

    tell transfer window 1 to open remote folder UploadDir1 -- go to the first upload directory

    -- do first bunch of uploads

    tell transfer window 1 to open remote folder home folder -- return to the login directory
    tell transfer window 1 to open remote folder UploadDir2 -- go to the second upload directory

    -- do second bunch of uploads

    and so on. That should work whether your UploadDir variables are of the form "Dir1" or "Dir1/Dir2".

    Let me know if that doesn't do the trick.

    Thanks,

    Jim Matthews
    Fetch Softworks

    Posted 9 years ago #

  • Jim Brandt Member

    Jim,

    Thanks for the reply. After playing around with lots of different things, I discovered the home folder setting.

    BTW, why does:

    set current folder to "/dir1/dir2"

    work on some FTP sites but on others it has to be:

    set current folder to "dir1/dir2"

    Is this a Windows server vrs Unix server vrs Mac server thing?

    Jim Brandt

    Posted 9 years ago #

  • Jim Matthews Administrator

    I'm not sure why that wouldn't work. If you'd like me to investigate, could you send me the contents of the Fetch Transcript window after you get the error?

    Thanks,

    Jim Matthews
    Fetch Softworks

    Posted 9 years ago #

  • Jim Brandt Member

    No, I just leave off the first "/" for every directory. I've put all my URLs, user IDs, Passwords, and directories into .plist files and everything is parameter driven. Its pretty easy to fix if I forget and put one in with a leading "/" the first time I try to connect and it fails. I just go into the .plist file, fix it and try again. It usually works after that and I don't have to mess with it.

    I was just curious if you knew why the leading "/" works for some sites and didn't for others.

    Posted 9 years ago #

  • Jim Matthews Administrator

    No, I don't have an offhand answer -- I'd have to look at the specifics of the situation.

    That sounds like an impressive system!

    Jim Matthews
    Fetch Softworks

    Posted 9 years ago #

Reply

  • Or nickname, if you prefer.
  • This will be kept confidential.
  • This is to ensure that you’re a person, not a spambot.