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

hi monks,

I am getting Stuck to copy a file from Unix OS

to Windows OS, how can i do this through programatically

please help me.

Thanks in advance

jakie

  • Comment on how can i copy a file from unix os to windows os

Replies are listed 'Best First'.
Re: how can i copy a file from unix os to windows os
by Corion (Patriarch) on Jun 15, 2004 at 08:45 UTC

    There are many ways, ranging from easy to hard.

    1. Use rsync - it makes keeping two directories in sync very easy and doesn't waste bandwidth. It works over rsh and ssh painless and there are clients for both Win32 and "Unix". Perl is not necessarily involved, but there also is Net::RsyncP.
    2. Use scp to transfer the files. Very easy, and Perl is not involved, but there also is Net::SSH and some SCP module.
    3. Use Net::FTP to transfer your files via ftp. This is less secure because the login and password will be transferred in clear text over the network, but may be a solution.
    4. Use LWP and serve your files on the Unix box via a web server. This restricts the access even less than ftp.
    5. Write your own server and client in Perl to transfer the files. This is the most ugly and overkill solution, but if you really are in need, a simple netcat-style server and client can pipe a .tar archive over a socket connection easily, and both server and client are typed in in about 10 lines of Perl.

    I would go and research the possibilities in the order as I presented them, but if you're really desperate, look at my netcat-style file pipes (sender and receiver) below:

    The sender (called nc for hysterical raisins):

    #!/usr/bin/perl -w use strict; use IO::Socket; select(IO::Socket::INET->new(PeerAddr => shift, PeerPort => shift) or +die "Couldn't connect: $!"); print for <>;

    The receiver (called cn for reasons obvious):

    #!/usr/bin/perl -w use strict; use IO::Socket; # reverse netcat my $s = IO::Socket::INET->new(LocalAddr => 'sfsifc53', LocalPort => 66 +66, Listen => 1) or die "Couldn't connect: $!"; my $c = $s->accept; print while <$c>;

    Most likely, the code above could be vastly simplified by using IO::All, but I haven't used that module yet.

Re: how can i copy a file from unix os to windows os
by Joost (Canon) on Jun 15, 2004 at 08:54 UTC
    In addition to the solutions mentioned above, if you share a directory-tree from a unix machine with windows machines using samba, all you have to do is write the file to, and read it from, to right location.

    Or you can run a web-server on the unix side, and run LWP::Simple on the client side. Anyway, you're too vague. Please answer one or more of the folowing questions:

    • Do you want the unix machine to intiate and execute the file transfer?
    • Do you have a network connection between the machines?
    • Do you maybe run both OS's on the same machine (like a dual-boot system) so you don't actually have the 2 OS's running on the same time?
    • Should the transfer be encrypted, or otherwise secured?
    • What do you do at the moment, if you transfer the files yourself?
    Joost
      hi,

      1) there are two different systems were one is

      installed by Unix Operating System and another

      one is installed by Windows Operating System.

      2)regarding the connection the Unix system is

      in Public Ip where the Windows system is in

      Private Ip

      3) both the Operating systems are not running on

      the same machine

      4) Actually i want to access a file which is in

      the Unix System from my Windows System.....

      *** How can i do a share directory-tree from a

      unix machine with windows machines using samba

      Kindly reply to this

      Thanks in advance

      Jakie
        Samba is a unix package that allows you to share directories that look to the windows machines like normal "shared folders", so you don't need any special software installed on the windows clients. I would not recommend to use it on a publicly accessible machine, however, for the same reasons you don't use shared folders on a publicly available windows machine.

        If you want to get the file off your unix machine from another machine, either install an FTP server on the unix machine and download it using Net::FTP or LWP, install a web-server and download using LWP, or - if you want to have encrypted connections, install an SSH server and use an SSH client library - or do system("scp user@remote:/file/path /local/path") if you have ssh and scp installed locally. Personally I like the ssh client programs from http://www.cygwin.com. If you want to run ssh without having to enter the password each time, you can set up public key authentication .

Re: how can i copy a file from unix os to windows os
by Roger (Parson) on Jun 15, 2004 at 10:23 UTC
    My unix system has Samba installed. All I have to do is to mount a Windows share, say, C:\Inbox, to /mnt/inbox on my Unix system:

    The command is:
    mount -t smbfs -o username=Roger,password=Blah //luke/inbox /mnt/inbox


    Then you can write to your share from Unix as if it's a local unix directory.

    Oh, by the way, your windows drive should be formatted with FAT32. Smbfs will only mount an NTFS partition as readonly.