Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Copying files between two systems using cgi/perl

by arajani (Novice)
on May 13, 2002 at 17:07 UTC ( [id://166225]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks,

I am trying to copy files between two systems (both win 2000).
One is server and another is normal system. The target system
has a shared directory which has full permissions to move the
files to. I am using the following chunk of code.
system("copy ..\text.html \\system1\shareddir");
I am in the server so I can access any file. In the above the
system1 is the system to which I intend to copy. If I invoke
the copy command from the command line I able to copy
successfully, but if I want to run the above system command
through my cgi/perl script its failing. Also in server
I can copy to different directories so I assume the problem
is not at the server. The error msg is 
Access is denied. 0 file(s) copied.

Any idea why I am having this error?

Thanks in advance,

Raj.

Replies are listed 'Best First'.
Re: Copying files between two systems using cgi/perl
by thunders (Priest) on May 13, 2002 at 17:38 UTC
    it's backslashitis plain and simple.
    system("copy ..\\text.html \\\\system1\\shareddir");

    should work. your "\t" is a tab "\\" interprolates to a single backslash and \s becomes a plain old s, if you do not escape your backslashes in a double quoted string.
    C:\>perl -e "print(qq|copy ..\text.html \\system1\shareddir|);" copy .. ext.html \system1shareddir
      If all else fails use an absolute path.
      system("copy \\full\\path\\to\\text.html \\\\system1\\shareddir");

      Who says that programmers can't work in the Marketing Department?
      Or is that who says that Marketing people can't program?
Re: Copying files between two systems using cgi/perl
by arajani (Novice) on May 13, 2002 at 18:29 UTC
    Hi All,

    Thanks for the many replies. Sorry .. I should have given
    the full code, to avoid the confusion. The double backslashes
    is infact in the code, so its not the issue.
    Let me more elaborate..
    
    my $sourcefile = 'c:/appl/process/attr_name.txt'; my $destination = '//System1/ShareDir'; $sourcefile = slashtobackslash($sourcefile); $destination = slashtobackslash($destination); system("copy $sourcefile $destination"); } sub slashtobackslash { my $value = $_[0]; $value =~ s-/-\\-g; return $value; }
    I am processing the file at the server side, and trying to
    copy to the target system. The target system has shared
    directory which has full permissions. When I copy from the
    server to this target system using copy command on command
    line, that works fine and the user is any user(administrator,
    or normal user which was being created).
    
    Regarding the cgi program user, the explanation I got from
    the IS group is may be the user might not have permissions,
    to write into any system, may be for the security issues.
    Well I wish I can be more specific, but as I am dealing
    with server, I dont have direct access to it. All the
    things I figured out till now are through cgi program and
    interacting with some one on IS and getting the feedback !!!
    Well about the return call of system command .. I will be
    checking now.
    
    IS dept. enabled the ftp from the server to the target system
    to the specific directory and may be I can use net::ftp module
    to implement this?
    use Net::FTP; $ftp = Net::FTP->new("targetsystem", Debug => 0); $ftp->login("anonymous"); $ftp->put("c:\\test11.pl"); $ftp->quit;
    I'm getting the following error ..
    Use of uninitialized value in concatenation (.) or string
    at C:/Perl/site/lib/Net/FTP.pm line 310.
    Any ideas?

    Thanks in advance,

    Raj.
      if you look at the code for the module Net::FTP(In my computer it's in Perl/site/lib/Net/FTP.pm) that line number in within the login() subroutine, more specifically it's in an unless block that gets called if you don't define a password,which if you code is accurate, you have not done.
      The actual code tries to do some gobbledegook with getpwuid($>) and $ENV{HOME} if you're not running unix, this could generate an undefined value, hence the error.
      So I would just go ahead and login as anonymous with an email as a password, you skip over the error condition that way.
      $ftp->login("anonymous","myemailaddress@somewhere.com");
Re: Copying files between two systems using cgi/perl
by particle (Vicar) on May 13, 2002 at 17:23 UTC
    system("copy ..\text.html \\system1\shareddir");
    are you checking the return code from system? the error message? why is 'copy' failing? where is the script running from? is the relative path to the file what you think it is? where is the code?

    ~Particle *accelerates*

Re: Copying files between two systems using cgi/perl
by tjh (Curate) on May 13, 2002 at 17:15 UTC
    Hmm. Could be serveral things. Share settings on the non-server (target?) machine? Login required?

      Typically, such problems are the result of environment differences -- in this case, the CGI-script is most likely not running as the same user that you are using to run the copy on the command line. Thus, it fails. Make sure that your CGI user has the permissions to perform this copy as well.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found