padawan_linuxero has asked for the wisdom of the Perl Monks concerning the following question:

I have a problem I need to do a program that can move file from the computer on to the server, they told me that via socket I could do it, so I read a bit and did these program
use IO::Socket; my $server = IO::Socket::INET->new( PeerAddr => 'localhost', PeerPort => 7888, Proto => 'tcp' ) or die "Can't create client socket: $!"; open FILE, "hello.txt"; print "Enviando informacion"; for (my $dots=1;$dots<=100;$dots++){ print "*"; } print "\n\n\n"; while (<FILE>) { print $_; print $server $_; } close FILE;
the server is this
use IO::Socket; my $server = IO::Socket::INET->new( Listen => 5, LocalAddr => 'localhost', LocalPort => 7888, Proto => 'tcp' ) or die "Can't create server socket: $!"; my $client = $server->accept; open FILE, ">out" or die "Can't open: $!"; while (<$client>) { print FILE $_; } close FILE;
but the thing is that these program only sends one program and I need to send many files that are store in a solder in my pc to the server but I have no idea on how to do that, can someone help me.
The ideas is simple on the flder of the PC everytime a file gets save there must be send to the server sometimes they save 2 or 15 files there so I need to send them all via socket to the server how can I do that? I have no idea can someone help me? thanks

Replies are listed 'Best First'.
Re: Send many file via socket
by samtregar (Abbot) on Apr 03, 2008 at 20:26 UTC
    Who is they in "they told me that via socket I could do it"? Did they also tell you that you couldn't use any of the many programs already written for this purpose like scp or ftp?

    Inventing your own file-transfer protocol seems like a fun way to waste a lot of time though. I'd do it by writing out a little MIMEy header for each file. Something like:

    Filename: foo.zip Size: 100010

    Then send the file, no encoding needed since the server knows how much data to expect. A new header could be sent after the file to send another file, or some kind of "All Done" message. The code for client and server should be easy to write.

    Of course this lacks all kinds of nice stuff that scp or ftp will do for you! Key stuff to worry about - security, wacky characters in filenames, losing the network connection in the middle of a transfer, etc.

    -sam

      Also, FTP and SCP both use sockets...so maybe by "use sockets", they meant use FTP or SCP or some otehr standard socket protocol. Maybe this is a test...to see whether or not he rolls his own.
Re: Send many file via socket
by CountZero (Bishop) on Apr 03, 2008 at 21:27 UTC
    Why not taking advantage from existing modules such as Net::FTPServer for the server side or Net::FTP or its bunch of derived modules for the client side?

    I see that Net::FTP::Simple has a method send_files() which allows you to give it a list of files to be FTP-ed in one bunch.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James