Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/perl
- use 5.016;
- use File::Copy;
- use Getopt::Long;
- use Cwd;
- #use re 'debug';
- use DDP;
- use Socket ':all';
- use Net::Address::IP::Local;
- use IO::Select;
- use Fcntl qw(F_SETFL O_NONBLOCK);
- use FindBin;
- Getopt::Long::Configure ('bundling');
- our $verbose = 0;
- our $help = 0;
- GetOptions(
- 'v|verbose+' =>\$verbose,
- 'h|help' =>\$help,
- );
- if ($help){
- print "There are some commands:
- ls to view files in directory
- cp to copy file to another directory with oppotunity to change the name
- rm to delete a file
- mv to rename a file
- mkdir to create a directory
- rmdir to delete a directory
- cat to get data from file in variable and show them
- touch to create a file
- exit to exit the program
- if you use '!...' you can use these command in local directory.
- You can also use flags:
- -h|--help to show this text
- -v|--verbose Program will display messages about, what actions it performs with what parameters.\n";
- exit();
- }
- print "Put a port:";
- my $port = <STDIN>;
- my $address = '127.0.0.1';
- socket my $c, AF_INET, SOCK_STREAM, IPPROTO_TCP or die $!;
- my $sa = sockaddr_in($port, inet_aton($address) ) or die $!;
- if ( connect($c, $sa) )
- {
- say "CONNECTED";
- }
- else
- {
- die $!;
- }
- my $s = IO::Select->new();
- for (\*STDIN, $c) {
- fcntl($_, F_SETFL, O_NONBLOCK) or die $!;
- $s->add($_);
- }
- our $currentdir = getcwd."/";
- while () {
- for my $fd ($s->can_read()) {
- while (my $std = <$fd> ) {
- if ($fd == $c) {
- say $std;
- }
- else {
- say "CLIENT: ";
- syswrite $c, $std or die $!;
- }
- }
- die "$!" unless $!{EAGAIN};
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement