You should also look at Net::FTP.

If you really need to do it with straight sockets, stick with IO::Socket. It's much easier to use than Socket, and is also part of the core. To "transfer" a file via sockets, it would involve a process like this:

  1. From the sending side, connect to the recieving side.
  2. Send some sort of header to the recieving side, stating such like the file size, send chunk size, etc.
  3. The recieving side should recieve this, validate, and then send a response.
  4. The sending side should recieve the response, open the file in binary mode (default on *nix; use binmode for windows), and then split the file into chunks of the agreed size (probably somewhere around 1000 bytes, leaving room for a validation header if you need it.).
  5. Each chunk should be sent separately; the next chunk should be sent after the reciever sends an "ok".
  6. The recieving side should re-assemble the file by stripping the headers and then writing it to a temp file. After recieving the entire file, it should move the temp file to its properly location and rename it.

Actual implementation details may vary, but you'd need to do something like this. I'd be much easier to use an existing protocol like FTP and an aforementioned module to compliment it.


:^) # Fear the wrath of the hyper smiley!

In reply to Re: File Transfer via Sockets by jryan
in thread File Transfer via Sockets by zentara

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, details, 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, summary, 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.