Command line in a cocoa app

Discussion in 'Mac Programming' started by italiano40, Jul 22, 2008.

  1. italiano40 macrumors 65816

    italiano40

    Joined:
    Oct 7, 2007
    Location:
    NY
    #1
    I am building this app that will download a txt file from a FTP with a command line command in it, and i want the program to run that command without opening a terminal how should i do this in cocoa
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    I'm not sure which part of this you are having trouble with, the FTP access or running the command.

    For running of the command the C way to do it would be to call system() and pass in the command as a c-style string. If this needs to be spawned but not block your main thread you could either add a & to the end of the command, or fork and in the child run the system command.

    For running the command the Cocoa way, NSTask is the way to go:
    http://developer.apple.com/document...Classes/NSTask_Class/Reference/Reference.html

    As far as the FTPing of a file, I'm not sure on that one. I will state that you should not use FTP but SFTP or another secure method of transmission. It's trivial to sniff FTP traffic, and in this case this would lead to someone being able to modify the file with the command to something like "rm -rf /users/*" and make you very unhappy.

    -Lee
     
  3. italiano40 thread starter macrumors 65816

    italiano40

    Joined:
    Oct 7, 2007
    Location:
    NY
    #3
    no i got the FTP down and i am think of switching to SFTP but i was also looking at e-mail, i just needed help with passing the command down to the command line, thanks
     

Share This Page