<?xml version="1.0" encoding="windows-1252"?>
<node id="329541" title="Re: Re: Transfer files (network)" created="2004-02-17 04:12:41" updated="2005-06-06 06:49:49">
<type id="11">
note</type>
<author id="180139">
AcidHawk</author>
<data>
<field name="doctext">
&lt;p&gt;There is no [cpan://Net::FTPServer] module for Windows.  So if [FireBird34] is running on a MS platform s/he will not be able to use it easily.&lt;/p&gt;&lt;p&gt;Have a look at creating a listening socket on the server and a client piece that connects to that socket.  &lt;/p&gt;&lt;p&gt;Below is some code I found (here at PerlMonks I think) that sets up a socket and transfers a file from the client.&lt;/p&gt;
&lt;readmore&gt;&lt;p&gt;&lt;b&gt;Server&lt;/b&gt;:-
&lt;code&gt;#!/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-&gt;new(
      Listen =&gt; 5,
      LocalAddr =&gt; 'localhost',
      LocalPort =&gt; $port ,
      Proto     =&gt; 'tcp'
  ) or die "Can't create server socket: $!";

  print "Server opened: localhost:$port\nWaiting clients...\n\n" ;

  while( my $client = $server-&gt;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) &lt; $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,"&gt;&gt;$data{filesave}") ; binmode(FILENEW) ;
        print FILENEW $buffer ;
        close (FILENEW) ;
        print "." ;
      }
      else {
      	print Dumper(%data);
      	last ;}
    }

    #print "OK\n\n" ;
  }
}

#######
# END #
#######
&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Client&lt;/b&gt;:-
&lt;code&gt;#!/usr/bin/perl

####################
# SEND FILE CLIENT #
####################

  use IO::Socket ;
  #$bandwidth = 1024*5 ; # 5Kb/s
	$bandwidth = 1024*1024 ; # 5Kb/s

  &amp;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 =&gt; $host,
     PeerPort =&gt; $port,
     Proto    =&gt; 'tcp',
     Timeout  =&gt; 30) ;

  if (! $sock) { die "ERROR! Can't connect\n" ;}
  $sock-&gt;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 #
#######

&lt;/code&gt;
&lt;div class="pmsig-180139"&gt;
-----&lt;BR&gt;
&lt;i&gt;Of all the things I've lost in my life, its my mind I miss the most.&lt;/i&gt;
&lt;/div&gt;</field>
<field name="root_node">
329517</field>
<field name="parent_node">
329520</field>
</data>
</node>
