Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

There is no Net::FTPServer module for Windows. So if FireBird34 is running on a MS platform s/he will not be able to use it easily.

Have a look at creating a listening socket on the server and a client piece that connects to that socket.

Below is some code I found (here at PerlMonks I think) that sets up a socket and transfers a file from the client.

Server:-

#!/usr/bin/perl #################### # SEND FILE SERVER # #################### use IO::Socket ; use Data::Dumper; my $port = $ARGV[0] || 6123 ; my $save_dir = './files' ; ############# # START SRV # ############# if (! -d $save_dir) { mkdir($save_dir,0755) ; print "Save directory created: $save_dir\n" ; } my $server = IO::Socket::INET->new( Listen => 5, LocalAddr => 'localhost', LocalPort => $port , Proto => 'tcp' ) or die "Can't create server socket: $!"; print "Server opened: localhost:$port\nWaiting clients...\n\n" ; while( my $client = $server->accept ) { print "\nNew client!\n" ; my ($buffer,%data,$data_content) ; my $buffer_size = 1 ; while (1) { if ( sysread($client, $buffer , $buffer_size) ) { # print "$buffer\n"; if ($data{filename} !~ /#:#$/) { print "Filename = $data{filename}\n"; $data{filename} .= $buffer ; } elsif ($data{filesize} !~ /_$/) { $data{filesize} .= $buffer ;} elsif ( length($data_content) < $data{filesize}) { if ($data{filesave} eq '') { $data{filesave} = "$save_dir/$data{filename}" ; $data{filesave} =~ s/#:#$// ; $buffer_size = 1024*10 ; if (-e $data{filesave}) { unlink ($data{filesave}) ;} print "Saving: $data{filesave} ($data{filesize}bytes)\n" ; } open (FILENEW,">>$data{filesave}") ; binmode(FILENEW) ; print FILENEW $buffer ; close (FILENEW) ; print "." ; } else { print Dumper(%data); last ;} } #print "OK\n\n" ; } } ####### # END # #######

Client:-

#!/usr/bin/perl #################### # SEND FILE CLIENT # #################### use IO::Socket ; #$bandwidth = 1024*5 ; # 5Kb/s $bandwidth = 1024*1024 ; # 5Kb/s &send_file( $ARGV[0] , $ARGV[1]||'localhost' , $ARGV[2]||6123 ) ; exit; ############# # SEND_FILE # ############# sub send_file { my ( $file , $host , $port ) = @_ ; if (! -s $file) { die "ERROR! Can't find or blank file $file" ;} my $file_size = -s $file ; my ($file_name) = ( $file =~ /([^\\\/]+)[\\\/]*$/gs ); print "Filename = $file_name\n"; my $sock = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port, Proto => 'tcp', Timeout => 30) ; if (! $sock) { die "ERROR! Can't connect\n" ;} $sock->autoflush(1); print "Sending $file_name\n$file_size bytes." ; print $sock "$file_name#:#" ; # send the file name. print $sock "$file_size\_" ; # send the size of the file to server. open (FILE,$file) ; binmode(FILE) ; my $buffer ; while( sysread(FILE, $buffer , $bandwidth) ) { print $sock $buffer ; print "." ; sleep(1) ; } print "OK\n\n" ; close (FILE) ; close($sock) ; } ####### # END # #######
-----
Of all the things I've lost in my life, its my mind I miss the most.

In reply to Re: Re: Transfer files (network) by AcidHawk
in thread Transfer files (network) by FireBird34

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [james28909]: two or three. if it has to do with how humans are handling said situations, then that is after they were able to evolve into those problems. agnostic means only believe with evidence. i took that from a tyson video
    [james28909]: and it seems that racism suggest that there is indeed a better race, but that is for evolution to decide
    [1nickt]: "right now, humans are smarter than in any of those times": define "smart"
    [erix]: ah, now you're appraoch downvote-territory ;)

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (11)
    As of 2017-12-15 14:57 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What programming language do you hate the most?




















      Results (433 votes). Check out past polls.

      Notices?