Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Socket:INET + Pipe to external program

Posted on 2004-08-01
Medium Priority
Last Modified: 2008-03-03
i want to write a perl file that starts a ftp program and then a udp server that listens for commands to send to the ftp program.

For tetsing purpose i used:
open(FTP, "|/home/user1/ftp/bin/ftp");
print FTP "open ftp://user:pass@";

So far everything works fine.
But if I add the INET Socket part it does not work anymore:

use IO::Socket::INET;
my $PASSWORD = 'test';open(FTP, "|/home/user1/ftp/bin/ftp") ;
my $sock = new IO::Socket::INET(LocalPort => 45720,Proto => "udp") || die @!;
printf "Waiting for message..\n";
while ($sock->recv($buf, 1024)) {
        chomp $buf;
        my ($password, $rcmd) = split(/ /, $buf);
        if ($password ne $PASSWORD) {
                printf "Wrong password from client (%s), ignoring request ..\n", $password;
        print FTP "open ftp://user:pass@";
        printf "New message .. %s \n",  $rcmd;
        printf "Waiting for next message..\n";
print FTP "quit";
exit 0;

This does not work as i thought it would.
I think the ftp program gets started (using ps -aux tells me it is running) but the line:
print FTP "open ftp://user:pass@";
is not sent to the program for some reason.

To avoid unnecessary questions:
I use: print FTP "open ftp://user:pass@";
for testing purpose later it should be print FTP "$rcmd"

Thank you
Question by:Bug2k3
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
LVL 28

Expert Comment

ID: 11689237
Why not use the Net::FTP module instead of the pipe to the external prgram?  The module will give you better control of the FTP connection, and provides error status and handling.


Author Comment

ID: 11689286
The external program comes with some extra functions the NET::FTP module does not have.
LVL 28

Expert Comment

ID: 11689319
What functions do you need?  The FTP module has some functions that are available to it but are not listed because they are inherited from Net::Netrc, Net::Cmd, and IO::Socket::INET.  Could those inherited functions be the ones you need?
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 11689352
Believe me, the things I use are not included in those components/modules.
And my question is not limited to ftp programs but to all command line applications in combination with the Socket:INET Server.
LVL 20

Accepted Solution

jmcg earned 1500 total points
ID: 11690608
You got this to work without sending line terminations down the pipe to the FTP command? That seems anomalous.

If it's necessary to use this external FTP application, you might prefer to run it under the control of something like the Expect module. When you send commands down the pipe, there is no reverse communication channel to see the results in your program.


Author Comment

ID: 11691462
Thanks for your answers. I solved the problem by disabling the puffering.
my $oldfh = select(FTP);
$| = 1;
I also added the line terminations and now it works fine.

So i think this problem is solved.
LVL 20

Expert Comment

ID: 11693408
Buffering was to be the next suspect, but I couldn't point a finger at it in the presence of your claim to have things working in that first example.

Since you've mostly solved this problem without our help, do you want to have this question PAQed and your points refunded?

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question