Uploading to ftp

Discussion in 'Mac Programming' started by thriftinkid, Apr 10, 2008.

  1. thriftinkid macrumors regular

    Mar 24, 2008
    Hey guys,

    I am trying to upload the contents of a folder to my ftp site. I tried using the upload to ftp action, and ftp transfer actions in automator. I they either don't upload the files, or they upload the first file, and then an error pops up, thus stopping my script. I then tried to write an applescript using my ftp application "cuteftp". The problem is the software has a tendency to lock up during transfers sometimes, and I want to make sure the connection is solid everytime. Is there any other applescript I can write to connect to my ftp server to make the file transfers? Somehow maybe using Mac OS Internet connect or something? I'm new to writing code, so please be patient with me. I'm not as smart as you guys. Thanks.
  2. yeroen macrumors 6502a


    Mar 8, 2007
    Cambridge, MA
    Can you ftp from the terminal command-line?

    If you try it, what do you see?
  3. psingh01 macrumors 65816

    Apr 19, 2004
    ncftp is another command that I've used to send entire directories to my host from a linux box. I don't think the regular ftp program recursively goes through all child directories, but I could be wrong.

    It doesn't seem to be on my Mac by default, but this is where you can download for osx.


    The two commands you need to look at are: ncftpget and ncftpput


    After getting this installed you would go to the terminal and type a command like:

    ncftpput -u bob -p bobspasswd -R ftp.somehost.com /remote/path /local/dir/to/send
  4. thriftinkid thread starter macrumors regular

    Mar 24, 2008
    I looked at the applescript dictionary for ftp commands, but didn't find any. It has a command to run a UNIX shell script or command, but that is way over my head. I have no idea where to start.

    I downloaded your suggested link, but I'm having a hard time even installing the program. When I say I'm new to writing code, imagine you are talking to a three year old, and you are drawing things out in crayon. : )
  5. psingh01 macrumors 65816

    Apr 19, 2004
    Ok :) On the link that I sent posted, you just need to install the client for OSX. Here are the direct links to the installers. If you have an intel mac choose the first one, if you have a ppc mac choose the second.


    Once you download it just install it like you would any other program. Double click the dmg file to mount the image (this might happen automatically when you are done downloading the file). Then go in that folder and double click the "NcFTP 3.2.1.pkg" to run the installer. Just click through the dialog until it is done installing.

    Now to run the program you have to go to the Terminal app in Applications/Utilities folder.

    In the terminal type:

    ncftpput -u USER -p PASSWORD -R HOST /remote/dir/path /local/dir/path

    You just have to replace USER, PASSWORD, HOST with your username, password and hostname of the server you will upload to.

    For /remote/dir/path replace that with the directory path on the server where you want to upload your files. For /local/dir/path just put the path to the directory you want to upload.

    As an example. On my laptop my username is psingh01 and I want to upload the directory "VacationPics" from my Desktop to my account on ftp.apple.com. On ftp.apple.com I have the username "ps123" and the password "secretpass". The directory on ftp.apple.com that I will upload to is "/home/ps123/vacpics".

    The command I would type would look like this:

    ncftpput -u ps123 -p secretpass -R ftp.apple.com /home/ps123/vacpics /Users/psingh01/Desktop/VacationPics

    Press Enter and you should see a little text message of it uploading. Or an error message if something went wrong.

    For more information on how ncftpput works, enter "man ncftpput" in the Terminal and it will display the help text. Use the arrows to move up and down the help page. Then type q to exit/quit the help page viewer.
  6. lazydog macrumors 6502a

    Sep 3, 2005
    Cramlington, UK
    You might try ftping from the command line to see if it's an ftp connection problem you're having in general rather than an automator one. If it is a connection problem then switching mode from active to passive… or passive to active… may solve your problem.

    b e n
  7. thriftinkid thread starter macrumors regular

    Mar 24, 2008
    Thanks so much man. You just solved my last problem in this script im writing. Your cooler then jesus with a mohawk.

    Actually there is one more thing. I just double checked my ftp server and realized it uploaded the the entire local folder. (folder included) Is there any way the script can look inside the folder and just upload any files inside?

    It's not a ftp problem, My application "cuteftp" is working just fine right now with the same login info.

    Also, upon running the same script with more then one file in the folder, the terminal shows the first file in the folder being completely uploaded, it times out and I get the following error:

    ncftpput /Users/John/Desktop/Finished: could not send file to remote host.

    When I look in the ftp folder it showed it was uploading to, the file isn't there? Any ideas?

    The Terminal Said it couldn't read the reply from control connection.
  8. psingh01 macrumors 65816

    Apr 19, 2004

    This is simple, just put a * at the end of your local path like this:

    ncftpput -u ps123 -p secretpass -R ftp.apple.com /home/ps123/vacpics /Users/psingh01/Desktop/VacationPics/*

    It will just look for contents inside VacationPics instead of uploading the folder VacationPics.

    Not sure about the other things. Try it on another server if you have access to it. It is possible that there is a firewall issue that is preventing your client from communicating with the server correctly. Which is probably the same issue you wrote about in the original post. I would also suggest just uploading one file at a time and see if that works with the command. If that works fine then your script might have to lookup filenames first, then call that command repeatedly for each file.

    One last thing. If you directory path has spaces in the name, then you must quotes around the file path or else the command will get confused with what is the correct filename. So if instead of VacationPics for the folder name, it was Vacation Pics, then you'll have to write the command like this:

    ncftpput -u ps123 -p secretpass -R ftp.apple.com /home/ps123/vacpics "/Users/psingh01/Desktop/Vacation Pics/*"

    This is true of all commands you run in the terminal, not just ncftpput. They use blank spaces to separate the different inputs.
  9. thriftinkid thread starter macrumors regular

    Mar 24, 2008
    I added the (*) and none of my alias's have space in them, so I will try at home, and if that doesn't work, then I guess it's back to the drawing board. Im writing a script with an ftp program called cyberduck. I'll see if that work too.Let me know if you have any other suggestions. Thanks again for all your help.
  10. larswik macrumors 68000

    Sep 8, 2006
    I too was looking last year for FTP uploading and programming in JAVA. I finally downloaded Transmit that came with plug ins for Automator. I can have it upload to one site and when it finishes it starts on the next site. When it is all done it emails me letting me know that it finished.


Share This Page