Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: scp file from windows10 to unix server

by syphilis (Archbishop)
on Feb 18, 2020 at 12:39 UTC ( [id://11113099]=note: print w/replies, xml ) Need Help??


in reply to scp file from windows10 to unix server

Just to confirm that I've struck similar issues (with various commands) over the years, and the first suggestion that haukex mentioned has worked, for reasons that I've never worked out.

I think the problem is that either the source file or the destination (probably the latter) is not being found.
If the scp executable was not being found you should instead get the following error:
'C:/Windows/System32/OpenSSH/scp' is not recognized as an internal or +external command, operable program or batch file.
Cheers,
Rob

Replies are listed 'Best First'.
Re^2: scp file from windows10 to unix server
by bliako (Monsignor) on Feb 18, 2020 at 18:01 UTC
    Just to confirm that I've struck similar issues (with various commands) over the years, and the first suggestion that haukex mentioned has worked, for reasons that I've never worked out.

    The difference is: system($cmd) runs the command (with its contained arguments) via a shell which is spawn first, whereas the system($exename, @args) calls the $exename command directly without the mediation of any shell (unless of course it is a shell-interpreted script). In Unix, the shell will take care of wildcard expansion *.xyz and the interpretation of special variables, e.g. ~/. So, there is a difference in what finally is run. In windows I don't know if the shell does anything and what. I am sure that, in any OS, the added layer will have its effect on metacharacter quotation and escaping ...

    If there is only one scalar argument, the argument is checked for shell metacharacters, and if there are any, the entire argument is passed to the system's command shell for parsing (this is /bin/sh -c on Unix platforms, but varies on other platforms). If there are no shell metacharacters in the argument, it is split into words and passed directly to execvp , which is more efficient. On Windows, only the system PROGRAM LIST syntax will reliably avoid using the shell; system LIST , even with more than one element, will fall back to the shell if the first spawn fails.

    (from system manpage)

    edit: removed a section and placed it in separate comment

    bw, bliako

      whereas the system($exename, @args) calls the $exename command directly without the mediation of any shell

      On Windows, "The issue is not the shell."

        very interesting reading, thanks.

        SQL has injections, C (and lots others) have buffer overflows, I wonder if there are no exploits for this quoting madness.

Re^2: scp file from windows10 to unix server
by vinoth.ree (Monsignor) on Feb 18, 2020 at 12:49 UTC
    Hi syphilis

    I got not recognized as an internal or external command error when I use just scp.exe instead of absolute path,

    I think the problem is that either the source file or the destination (probably the latter) is not being found.

    But I am able to run it in cmd line without issues.


    All is well. I learn by answering your questions...
      I got not recognized as an internal or external command error when I use just scp.exe instead of absolute path,

      If you want to run the command as simply scp.exe or scp then you'll need to add C:/Windows/System32/OpenSSH to the PATH:
      set PATH=%PATH%;C:\Windows\System32\OpenSSH
      But I am able to run it in cmd line without issues

      Yes, I understand that.
      I'm just saying that when I've struck this type of issue in the past, the first approach that haukex suggested of replacing system($cmd) with system(@cmd) has often worked for me.
      That's the first thing I'd be trying.
      Oh ... and use warnings; if they're not already enabled.

      Cheers,
      Rob
      I think the problem is that either the source file or the destination (probably the latter) is not being found.

      You don't need to guess: As I said, better error handling in Perl will help, and also you can always try things at the command line and compare the errors you get: Try using the command line to copy a file that doesn't exist locally, and to a destination that causes an error.

        Hello haukex,

        I got the issue, I am using this perl script as sourcetree's custom action, though I added this "C:/Windows/System32/OpenSSH" path into PATH env variable, this application is not accounting into the path variable, always keep on says "The system cannot find the path specified." I just copied OpenSSH folder to my home path then it started to work.


        All is well. I learn by answering your questions...
Re^2: scp file from windows10 to unix server
by vinoth.ree (Monsignor) on Feb 18, 2020 at 13:10 UTC

    To confirm the same I removed the destination path and let the scp.exe to copy the file to my home directory as below,

    C:/Windows/System32/OpenSSH/scp.exe D:/dev/eee/src/sample.dat vinothg@ipaddress:

    But got the same error


    All is well. I learn by answering your questions...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-19 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found