problem reading remote file.

Discussion in 'Perl Misc' started by kath, Feb 16, 2007.

  1. kath

    kath Guest

    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.
    kath, Feb 16, 2007
    #1
    1. Advertising

  2. kath

    Mirco Wahab Guest

    kath wrote:
    > 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.
    Mirco Wahab, Feb 16, 2007
    #2
    1. Advertising

  3. Mirco Wahab <> wrote:

    > 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?

    :)


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Feb 16, 2007
    #3
  4. kath

    Mirco Wahab Guest

    Tad McClellan wrote:
    > Mirco Wahab <> wrote:
    >
    >> 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?
    >
    > :)


    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.
    Mirco Wahab, Feb 16, 2007
    #4
  5. kath

    Ala Qumsieh Guest

    Tad McClellan wrote:

    > Mirco Wahab <> wrote:
    >
    >> 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?


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

    my $arg = shift;

    fortunately, strict doesn't like filthy code.

    --Ala
    Ala Qumsieh, Feb 17, 2007
    #5
  6. kath

    kath Guest

    On Feb 16, 3:23 pm, Mirco Wahab <> wrote:
    > kath wrote:
    > > 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.


    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.
    kath, Feb 17, 2007
    #6
  7. kath

    Joe Smith Guest

    kath wrote:

    > 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
    Joe Smith, Feb 18, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Trevor
    Replies:
    1
    Views:
    638
    Steven Cheng[MSFT]
    May 30, 2005
  2. Trevor
    Replies:
    1
    Views:
    4,141
    Steven Cheng[MSFT]
    Jun 6, 2005
  3. Replies:
    0
    Views:
    771
  4. Dayton Jones

    Remote.pm (File::Remote) problem

    Dayton Jones, Mar 1, 2006, in forum: Perl Misc
    Replies:
    9
    Views:
    173
    Dayton Jones
    Mar 3, 2006
  5. Adrian

    Reading a remote file or page?

    Adrian, Jan 17, 2006, in forum: Javascript
    Replies:
    2
    Views:
    84
    Adrian
    Jan 17, 2006
Loading...

Share This Page