7 Replies Latest reply: Feb 20, 2011 10:51 AM by nick_harambee
nick_harambee Level 1 (5 points)

I have created a script which successfully uploads files to my server using FTP and a curl command.

The one thing I haven't worked out how to do is how to create a directory on my server using applescript. At the moment I have to manually create the correct directory for the script to work, but would like to be able to automate everything.

Would this be possible?



Macbook Pro, Mac OS X (10.6.4), 2.66 GHz Intel Core i7 8GB RAM
  • Bernard Harte Level 4 (3,220 points)
    from http://curl.haxx.se/docs/manpage.html


    (FTP/SFTP) When an FTP or SFTP URL/operation uses a path that doesn't currently exist on the server, the standard behavior of curl is to fail. Using this option, curl will instead attempt to create missing directories.
  • Camelot Level 8 (46,650 points)
    curl has a --ftp-create-dirs switch that tells it to create remote directories if needed, so just incorporate that switch in your existing shell command and you should be set.
  • nick_harambee Level 1 (5 points)
    Thanks for these responses.

    The shell command is:

    do shell script ("curl -T " & outPath & " -u " & ftp_entire)

    I'm not sure where to include --ftp-create-dirs
  • Bernard Harte Level 4 (3,220 points)
    I am pretty sure you would do:

    do shell script ("curl -T --ftp-create-dirs " & outPath & " -u " & ftp_entire)
  • nick_harambee Level 1 (5 points)
    Thanks Bernard.

    I have tried that and still get the error message:

    "curl: Can't open '--ftp-create-dirs'!
    curl: try 'curl --help' or 'curl --manual' for more information
    % Total % Received % Xferd Average Speed Time Time Time Current
    Dload Upload Total Spent Left Speed

    0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
    curl: (9) Server denied you to change to the given directory"

    The other relevant parts of the script are:

    set ftp_url to "ftp.****.org.uk/artists/" & artistName2 & "/assets/"
    set ftp_username to "*****@*****.org.uk"
    set ftp_password to "****"
    set ftp_entire to ftp_username & ":" & ftp_password & " ftp://" & ftp_url

    set outPath to outputFolder & fileCounter & ".jpg"

    and then...

    do shell script ("curl -T --ftp-create-dirs " & outPath & " -u " & ftp_entire)

    Like I said, all works fine when the directories are already in place. I have permissions for the artists folder set to "777", i.e. writable. Because the script is trying to create two directories at once, i.e. "artistName2" and then "assets" under it, I wondered if this was significant, but then I tried with just one new directory, and still got the error.
  • Camelot Level 8 (46,650 points)
    do shell script ("curl -T --ftp-create-dirs " & outPath & " -u " & ftp_entire)

    The -T switch tells curl the file to upload, which has to be the next argument on the command line, therefore this is getting interpreted as telling curl to upload the file '--ftp-create-dirs', hence the failure.

    The solution to to just re-order the parameters:

    do shell script ("curl --ftp-create-dirs -T " & outPath & " -u " & ftp_entire)

    (that is, assuming that outPath is the path to the file to be uploaded)
  • nick_harambee Level 1 (5 points)
    Ah, thanks a lot Camelot. That works fine.