Your bottleneck may be the network connection. Compress the text file before sending, uncompress it after receiving. You don't need any perl for that, a shell command is sufficient:

>gzip -c < /etc/passwd | ssh remotehost 'gzip -dc > /tmp/passwd' >ssh remotehost head /tmp/passwd root:x:0:0::/root:/bin/bash bin:x:1:1:bin:/bin:/bin/false daemon:x:2:2:daemon:/sbin:/bin/false adm:x:3:4:adm:/var/log:/bin/false lp:x:4:7:lp:/var/spool/lpd:/bin/false sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/:/bin/false news:x:9:13:news:/usr/lib/news:/bin/false >

gzip is just one option, bzip2 and xz usually compress a little bit better, but need more CPU power and/or RAM than gzip, and are not available everywhere. Both are drop-in replacements for gzip, they support at least the classic command line arguments of gzip.

Note that text files usually compress very well, unlike other files. Trying to compress an already compressed file, like a ZIP or JPEG file, just wastes CPU cycles.

Another option is to use rsync IF you transfer the same file over and over again, after editing or appending to it. rsync also trades CPU power for bandwidth, and tries quite hard not to transfer file parts that are already present at the remote host.

A third option for editing and re-transmitting the same file is to use diff on the local host and patch on the remote host. Patches are usually much smaller than the original file.

And, of course, if you suspect that modules written in Perl reimplementing standard unix utilities are slow, try using the original utility. The original is usually written in C or C++, and compiled using a highly optimizing compiler. So they have less startup time and less overhead than perl. In other words, try ssh, sftp, ftp.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re: faster alternatives to Net::FTP and Net:LSFTP by afoken
in thread faster alternatives to Net::FTP and Net:LSFTP by KSHYAMKUMAR

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.