problem reading remote file.

K

kath

Hello,

I have a script to read remote file. The script goes as follows,

#!C:\Perl\bin\perl.exe

$remote= '\\\remotehost\remotedir\remotefile.jml';
open(fp, $remote) or die ("could not open the file");

print while(<fp>);

close(fp);

This script runs fine on my windows machine. But the same script when
I run in UNIX, after changing the shebang line to /usr/bin/perl, I
get

could not open the file file_name.pl at 4

The remote host from which I am trying to read the file is also
Windows box.


1. where am i making wrong?
2. Why the script is not running on UNIX?


Thank you,
Regards,
kath.
 
M

Mirco Wahab

kath said:
I have a script to read remote file. The script goes as follows,
#!C:\Perl\bin\perl.exe
$remote= '\\\remotehost\remotedir\remotefile.jml';
open(fp, $remote) or die ("could not open the file");
print while(<fp>);
close(fp);
This script runs fine on my windows machine. But the same script when
I run in UNIX, after changing the shebang line to /usr/bin/perl, I
get
could not open the file file_name.pl at 4

The remote host from which I am trying to read the file is also
Windows box.
1. where am i making wrong?
2. Why the script is not running on UNIX?

Under Unix, you need to have access to the
windows box by smbclient and fiends.

Your code traanslated to the unix world
could read like the following:

use strict;
use warnings;

# this is what you used to use
my $winrmt = '\\\remotehost\remotedir\remotefile.jml';

# make sure you get the access rights correct,
# maybe you can drop username/password completely
my $unxrmt = '-n --username=kath --password=kath01 smb:/'
. join '/', split /\\+/, $winrmt;

# pull some adrenaline:
print "trying: $unxrmt \n";

my $pid = open HANDLE, "smbget $unxrmt |" or die "fork error: $!";
close HANDLE;

# now your remote file should reside in your current
# directory. Please check out other options if the
# smbclient family e.g.: $> man smbget

If it won't work, check out what $unxrmt looks like
and pot it back here ...

Regards

M.
 
T

Tad McClellan

Mirco Wahab said:
Under Unix, you need to have access to the
windows box by smbclient and fiends.
^^^^^^

Did you do that on purpose, or is it an (entertaining) Freudian slip?

:)
 
M

Mirco Wahab

Tad said:
^^^^^^

Did you do that on purpose, or is it an (entertaining) Freudian slip?

:)

Ooops,

sometimes I'd really try hard to be "funny" -
but here I was just typing during a telephone
conversation with someone else ...

Sorry ;-)

M.
 
A

Ala Qumsieh

Tad said:
^^^^^^

Did you do that on purpose, or is it an (entertaining) Freudian slip?

Very often I forget the 'f' in code like this:

my $arg = shift;

fortunately, strict doesn't like filthy code.

--Ala
 
K

kath

Under Unix, you need to have access to the
windows box by smbclient and fiends.

Your code traanslated to the unix world
could read like the following:

use strict;
use warnings;

# this is what you used to use
my $winrmt = '\\\remotehost\remotedir\remotefile.jml';

# make sure you get the access rights correct,
# maybe you can drop username/password completely
my $unxrmt = '-n --username=kath --password=kath01 smb:/'
. join '/', split /\\+/, $winrmt;

# pull some adrenaline:
print "trying: $unxrmt \n";

my $pid = open HANDLE, "smbget $unxrmt |" or die "fork error: $!";
close HANDLE;

# now your remote file should reside in your current
# directory. Please check out other options if the
# smbclient family e.g.: $> man smbget

If it won't work, check out what $unxrmt looks like
and pot it back here ...

Regards

M.

hi, I do not see the post I done before, so i am reposting,

Hi Wahab, thanks for the reply. I was not aware of the smb* commands.
You made me to learn this new command. The output of $unxrmt was
correct, and tried to run the same at console(command-prompt) but I
get,

You don't have enough permissions to access smb://remotehost/remotedir/remotefile.jml

but when use the same( open(filehandle, remotefile) ) function I do
not get message like, you don't have enough permission. Its expecting
the username and password.

Why that don't ask when I try access the same location on Windows,
though I was not using smbclient family commands on windows.

Do i need to download the file(s) first prior reading it(I do not do
that, as you can see in the above code )?



Thanks,
Regards,
kath.
 
J

Joe Smith

kath said:
You don't have enough permissions to access smb://remotehost/remotedir/remotefile.jml

That usually means you did not provide the right credentials (username + password).
Why that don't ask when I try access the same location on Windows,

On Windows, it remembers the password you used to log into the system with,
and provides your username and password whenever accessing a remote server's
file share.

Unix is not Windows. Your Windows username and password have no meaning for
Unix. You have to provide your credentials to whatever Unix is using to
access the Windows file share.
though I was not using smbclient family commands on windows.

You're using the SMB protocols every time you use the UNC (Uniform Naming
Convention or UNC) such as "\\remotehost\sharename\remotefile".
Do i need to download the file(s) first prior reading it(I do not do
that, as you can see in the above code )?

Unix has its own naming conventions - it does not use the Windows UNC.
Unless you have root (Administrator) privileges on Unix, you cannot expect
to be able to access a Windows file share as a Unix file system.
You'll have to fetch the data from the Windows file and store it as
a Unix file, or open a piped command and read the data sequentially.

-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top