• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTask ftp < file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTask ftp < file


  • Subject: Re: NSTask ftp < file
  • From: Gwynne <email@hidden>
  • Date: Sat, 23 Apr 2005 04:19:34 -0400

On Apr 23, 2005, at 3:41 AM, Camille GOUREAU-SUIGNARD wrote:
I've got a problem and found no repose in the archives.

I've got a ftp command file called toto.txt
When in the terminal I do :
ftp ftp://me:email@hidden < /pathToDirectory/toto.txt
it work perfectly

But when I use it through cocoa it doesn't work:

task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/bin/ftp"];
[task setArguments: [NSArray arrayWithObjects: @"ftp://me:email@hidden";, @"<", @"toto.txt", nil]];
[task launch];


The run log shows the output for connection, but after that enters the ftp command editor and wait for an entry

	ftp> |

I think the problem lies in a standard output or something like that, but I cant figure it out.

Thanks for help

The < redirection is performed by the shell, not the ftp process. Thus when you launch ftp directly with NSTask, it treats it as if it had two arguments, rather than routing stdin to the text file. You have several options to do what you want:


1) Launch a shell instead of ftp, as in:
[task setLaunchPath:@"/bin/sh"];
[task setArguments:[NSArray arrayWithObjects:@"-c", [NSString /*YOU MUST WRITE THIS METHOD */stringByAddingShellEscapes:@"/usr/bin/ftp ftp://me:email@hidden < toto.txt"], nil]];


2) Perform the redirection yourself, the way the shell does:
[task setLaunchPath:@"/usr/bin/ftp"];
[task setStandardInput:[NSFileHandle fileHandleForReadingAtPath:@"/full/path/to/toto.txt"]];
[task setArguments:[NSArray arrayWithObject:@"ftp://me:email@hidden";]];


I strongly recommend AGAINST using 1, as it presents issues with shell escapes in the path to the file that the other method avoids.

There are several other methods as well; these are the ones that spring to mind as the most Cocoa-ish. All code written in Mail, standard disclaimers apply :).

-- Gwynne, daughter of the Code
Website: http://musicimage.plasticchicken.com/
"This whole world is an asylum for the incurable."

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >NSTask ftp < file (From: Camille GOUREAU-SUIGNARD <email@hidden>)

  • Prev by Date: NSTask ftp < file
  • Next by Date: Where does Undo fit in MVC
  • Previous by thread: NSTask ftp < file
  • Next by thread: Where does Undo fit in MVC
  • Index(es):
    • Date
    • Thread