Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

write/read to remote machine

by hari9 (Sexton)
on Jul 27, 2010 at 21:27 UTC ( #851612=perlquestion: print w/replies, xml ) Need Help??

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

Hi dear all!

I'm trying to write/read files into/from a remote machine. The machine1,
I'm working on is linux, and I try writing into machine2, windows.

#open the directory you want to create file in. syntax of the form (i believe): ipaddress\C:\Users\folder_name\ opendir(DR,"\\10.64.30.27\C$\Users\hari9\"); #create the file. open(file,">drive1.txt); for($i=0;$i<=10;$i++) {print file $i; } closedir (DR); close (file);

If I were to write from windows into a linux machine please suggest me the syntax. ( my linux machine is a virtual machine)

file::Remote wouldnt work since its only for unix.

Samba's downloads files are neither working on my windows.

Any help would be appreciated.

Replies are listed 'Best First'.
Re: write/read to remote machine
by runrig (Abbot) on Jul 27, 2010 at 21:37 UTC
    Not that it'll help much in your case, but if opendir or open fail, you should display the associated error message, e.g.:
    open(my $fh,">drive1.txt) or die "Error opening file: $!";
    In any case, did you read and do you understand what opendir does? I do not think it does what you think it does.

    To help with your problem, can you ftp or scp files to the linux machine? putty runs on windows and has ssh/scp clients.

      opendir, It opens a a new folder under the given path ( the last part of the path being the new folder you want to create)

      I tried writing the same code on windows, and it worked.

      I use Putty to logon to the unix machine, but should ssh/scp code be included in the perl script?

      Thanks for the reply!
        opendir, It opens a a new folder under the given path ( the last part of the path being the new folder you want to create)
        No, did you read the documentation? Or the documentation for readdir that the first docs link to for a usage example?
        I use Putty to logon to the unix machine, but should ssh/scp code be included in the perl script?
        Yes, if you don't want to or are unable to set up samba on the linux machine. Does a plain file copy from the command line work? Is samba already set up?
Re: write/read to remote machine
by monk2b (Pilgrim) on Jul 27, 2010 at 21:56 UTC
    AFAIK, you will only be able to mount windows from Linux using cifs or smbfs. In my world Linux uses Samba for both. Samba does not run on your Windows computer it only needs to run on your Linux computer.

    If you run this command on a Redhat and most likely any other Linux computer you can see if Samba is running. You should see processes for smbd -d and nmbd -D running

    ps -aux | grep mbd

    If samba is running I use this command on my Linux servers to run perl scripts on Windows file system all the time.

    $mp = "/mnt/mylinuxmountpoint"; $winshare = "//windowsservername/windowsshare"; RHEL3 $mount = "/bin/mount -t smbfs -o username=hari9,password=hari9passwor +d,workgroup=hari9doomainname"; Older versions of the 2.4 kernel use smbfs and newer versions use cifs +. RHEL5 $mount = "/bin/mount -t cifs -o username=hari9,password=hari9password +,workgroup=hari9doomainname"; sub Mnt { my ($mntcmd,$mount,$share,$mp); ($mount,$share,$mp) = @_; $mntcmd = "$mount $share $mp"; system("$mntcmd"); } Mnt($mount,$winshare,$mp);
    Perl Good - Manual process bad
Re: write/read to remote machine
by roboticus (Chancellor) on Jul 27, 2010 at 21:54 UTC

    hari9:

    Hmmm ... interpolation and backslashes are giving you a different directory than you're wanting. Use forward slashes instead of backslashes, use single quotes, or double your backslashes. Also, $\ is a special variable, so using single quotes would prevent that from interpolating.

    ...roboticus

      I tried putting the path in single quotes and it worked as I expected in windows machine.(removed the ip address of the local machine in that case.), still didnt work.

      Thanks for your reply

        Did you double-up on the backslashes? The single quotes prevents $\ from interpolating, but '\\' still converts to '\':

        Roboticus@Roboticus-PC ~ $ cat interp.pl #!/usr/bin/perl print '\\10.64.30.27\C$\Users\hari9', "\n"; print '\\\\10.64.30.27\\C$\\Users\\hari9', "\n"; Roboticus@Roboticus-PC ~ $ perl interp.pl \10.64.30.27\C$\Users\hari9 \\10.64.30.27\C$\Users\hari9

        ...roboticus

Re: write/read to remote machine
by nikosv (Deacon) on Jul 29, 2010 at 14:46 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://851612]
Approved by AnomalousMonk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2022-07-03 15:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?