- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Perl code to transfer text strings. Need to tr...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2006 08:43 AM
10-13-2006 08:43 AM
below to transfer a file and not just text
strings. Two parts. A client socket part and
a server socket(daemon) part.
socket.client.pl
#!/usr/bin/perl
#===============================================
# Client -- using object interface
# Support Windows and UNIX
#===============================================
use IO::Socket;
my $sock = new IO::Socket::INET (
PeerAddr => '128.166.11.28',
PeerPort => '9999',
Proto => 'tcp',
);
die "Could not create socket: $!\n" unless $sock;
print $sock "Hi there!\n";
$sock->send("Hi again!\n");
close($sock);
----------------------------------------------
socket.server.pl - enclosed also.
#!/usr/bin/perl
#===============================================
# Server -- using object interface
# Support Windows and UNIX
#===============================================
#use Proc::Daemon;
use IO::Socket;
#Proc::Daemon::Init();
use POSIX qw(setsid);
sub daemonize {
die "Can't fork" unless defined (my $child = fork());
exit 0 if $child;
setsid();
open(STDIN, "open(STDOUT, ">/dev/null");
open(STDERR, ">&STDOUT");
chdir '/';
umask(0);
$ENV{PATH} = '/bin:/sbin:/usr/bin:/usr/sbin';
return $$;
};
&daemonize;
while() {
my $sock = new IO::Socket::INET (
LocalAddr => '128.166.11.28',
LocalPort => '9999',
Proto => 'tcp',
Listen => 5,
Reuse => 1,
);
die "Could not create socket: $!\n" unless $sock;
my $new_sock = $sock->accept();
####################################
# Put a message to file. #
####################################
while(defined($Line = <$new_sock>)) {
open (F,"+>>/var/adm/syslog/socket.server.perl.log");
print F $Line;
system($Line);
close F;
};
close($sock);
}; #End of while cycle
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2006 07:05 PM
10-15-2006 07:05 PM
Solutionnot quite sure what you mean. YOu can not "transfer" a file via a socket, but you can transfer the file contents via the socket.
If that is what you want to do, you should be able to enclose your
print $sock "Hi there!\n";
$sock->send("Hi again!\n");
statements with a loop, which read the input file line by line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2006 07:55 AM
10-16-2006 07:55 AM
Re: Perl code to transfer text strings. Need to transfer file.
just transfer a file. If only the contents
of the file, line by line can be transfered, then I would not know how to do that since
my perl coding sucks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2006 01:53 AM
10-17-2006 01:53 AM
Re: Perl code to transfer text strings. Need to transfer file.
The good news is that it really isn't necessary to reinvent the wheel; just use the Net::FTP module and everything will be done for you. If you like, you can choose a non-standard port. Also (and I have not bothered to search because I do not reward laziness), if there is a need for some task there is likely already a module to do that task (or something very close to it). Search the modules at www.perl.org/CPAN and you may very well find exactly what you are looking for.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2006 03:33 AM
10-17-2006 03:33 AM
Re: Perl code to transfer text strings. Need to transfer file.
I would suggest to have a deko at "perldoc perlipc".
It explains the basics of inet socket IPC with lots of valuable code snippets in Perl.
I'm sure it will spark an idea.
Basically it doesn't matter what kind of data you send over a socket pair wire, be it ascii or binary.
Only does your client need to know how to handle it.
For instance the client could even read per single byte via a sysread() in a while loop,
though this is not terribly efficient,
as is also constated in the above mentioned POD.
But as Clay mentioned, why do you want to burden yourself with typical socket coding morass like establishing a proper protocol,
preventing deadlocks, struggling with buffering issues (n.b. don't forgot to autoflush either via $|, or the autoflush method of IO::Handle) while there are lots of higher tcp level modules available whose authors already have gone through all this?
Well, maybe self-education, or very specific needs would justify it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2006 08:21 AM
10-17-2006 08:21 AM
Re: Perl code to transfer text strings. Need to transfer file.
Net::FTP or even just a shell script, which
I use all of them today, which I just pass
parms to. But they all require a login id
and password. Which they do not want
hardcoded in any script. Guess I could
just use Openssh scp .
Thanks for you inputs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2006 08:29 AM
10-17-2006 08:29 AM
Re: Perl code to transfer text strings. Need to transfer file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2006 09:16 AM
10-17-2006 09:16 AM
Re: Perl code to transfer text strings. Need to transfer file.
Security note: ftp authenticates in clear text.
.netrc files contents can become known compromising security on the server.
Always disable root ftp on your servers.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com