Netcat frontend - please help

P

Piotrek

Hello,

I have a task to write a ftp client using a compiled version of linux
netcat. I figures this would be a good way to learn perl ;)

What I need to do is to take the default input and output from a
launched netcat prog. and make a frontend.

I need to do something like (in pseudo): if (INPUT == "331 Password
required for xxx") { print("PASS xxx1"); } , make a command prompt and
some commands like if (COMMAND == "ls") { print("DIR"); }.

Can You tell me how to do that?

Especially how to reditect the input/output and script it.

Thank You!
 
B

Ben Morrow

Quoth (e-mail address removed) (Piotrek):
I have a task to write a ftp client using a compiled version of linux
netcat. I figures this would be a good way to learn perl ;)

What I need to do is to take the default input and output from a
launched netcat prog. and make a frontend.

I need to do something like (in pseudo): if (INPUT == "331 Password
required for xxx") { print("PASS xxx1"); } , make a command prompt and
some commands like if (COMMAND == "ls") { print("DIR"); }.

If this isn't homework, use Net::FTP instead.
Otherwise, do your work yourself.

Ben
 
I

Ian Wilson

Piotrek said:
Hello,

I have a task to write a ftp client using a compiled version of linux
netcat. I figures this would be a good way to learn perl ;)

I'd have thought it was better to use one of Perl's FTP modules. To me,
this would be a more natural way of using Perl. Search CPAN for FTP.

Otherwise program Sockets directly, it's not that hard in Perl. The
Camel book used to have examples of this.
What I need to do is to take the default input and output from a
launched netcat prog. and make a frontend.

There is already a program that does this kind of thing, called Expect.
In addition, Perl has an "Expect" module.
I need to do something like (in pseudo): if (INPUT == "331 Password
required for xxx") { print("PASS xxx1"); } , make a command prompt and
some commands like if (COMMAND == "ls") { print("DIR"); }.

Can You tell me how to do that?

I imagine the main complication will be timeouts and trapping & handling
of exceptions & errors. Expect makes this easier. I find that dialogues
with interactive programs often seem much more event driven than linear.
Especially how to reditect the input/output and script it.

Have you looked in "Learning Perl" by O'Reilly, or their "Perl CookBook"?

If I was a Perl neophyte, I'd find a better problem for a learning
exercise than this one. YMMV.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top