Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何启用Windows';从Python使用scp?_Python_Windows_Scp - Fatal编程技术网

如何启用Windows';从Python使用scp?

如何启用Windows';从Python使用scp?,python,windows,scp,Python,Windows,Scp,我可以从命令行执行scp.exe,但不能从Python执行: (dev) go|c:\> scp usage: scp [-346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program] source ... target (dev) go|c:\> python -c "import os;os.system

我可以从命令行执行
scp.exe
,但不能从Python执行:

(dev) go|c:\> scp
usage: scp [-346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program] source ... target

(dev) go|c:\> python -c "import os;os.system('scp')"
'scp' is not recognized as an internal or external command,
operable program or batch file.
尝试使用绝对路径:

(dev) go|c:\> whereis scp
C:\Windows\System32\OpenSSH\scp.exe

(dev) go|c:\> python -c "import os;os.system(r'C:\Windows\System32\OpenSSH\scp.exe')"
The system cannot find the path specified.
Python甚至无法列出目录:

(dev) go|c:\> python -c "import os;len(os.listdir(r'C:\Windows\System32\OpenSSH'))"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
WindowsError: [Error 3] The system cannot find the path specified: 'C:\\Windows\\System32\\OpenSSH\\*.*'
并包含
scp.exe

(dev) go|c:\Windows\System32\OpenSSH> dir
 Volume in drive C is OS
 Volume Serial Number is 4C4D-147C

 Directory of c:\Windows\System32\OpenSSH

02/12/2019  03:15 AM    <DIR>          .
02/12/2019  03:15 AM    <DIR>          ..
09/15/2018  11:09 AM           322,560 scp.exe
02/12/2019  03:12 AM           322,048 sftp-server.exe
09/15/2018  11:09 AM           390,144 sftp.exe
09/15/2018  11:09 AM           491,520 ssh-add.exe
09/15/2018  11:09 AM           384,512 ssh-agent.exe
09/15/2018  11:09 AM           637,952 ssh-keygen.exe
09/15/2018  11:09 AM           530,432 ssh-keyscan.exe
02/12/2019  03:12 AM           149,504 ssh-shellhost.exe
09/15/2018  11:09 AM           882,688 ssh.exe
02/12/2019  03:14 AM           974,848 sshd.exe
02/12/2019  03:12 AM             2,253 sshd_config_default
              11 File(s)      5,088,461 bytes
               2 Dir(s)  812,082,962,432 bytes free

但是我不知道如何在这里赋予Python正确的权限…?

您可能正在64位Windows中使用32位Python。WOW64将访问
“%SystemRoot%\System32”
重定向到
“%SystemRoot%\SysWOW64”
。大多数可执行文件以32位版本分发,但有些程序只有64位。这包括整个OpenSSH目录。在Windows 7+中,WOW64使本机System32目录可用作
“%SystemRoot%\SysNative”
。它不是一个真正的目录,所以它只能在64位Windows中运行的32位程序中工作。或者只安装64位Python。关于OpenSSH目录的安全性,桌面应用程序的访问检查基于调用方访问令牌中的已启用组。系统评估访问控制列表中的每个条目,直到授予所有必需的访问权限,或拒绝某些必需的访问权限。按照规范,首先列出拒绝条目,但在本例中,无论如何都不存在拒绝条目。这些都是允许输入的。我们可以看到,标准用户(即启用“BUILTIN\users”组的呼叫者)被授予对该目录的读取权限,因此您有权列出该目录。如果你没有,你会得到一个
PermissionError
@eryksun,我甚至不会想到32/64的问题。使用64位Python解决了这个问题。如果你创造一个答案,我会给你分数…-)使用64位版本的python对我也很管用。谢谢
(dev) go|c:\Windows\System32\OpenSSH> dir
 Volume in drive C is OS
 Volume Serial Number is 4C4D-147C

 Directory of c:\Windows\System32\OpenSSH

02/12/2019  03:15 AM    <DIR>          .
02/12/2019  03:15 AM    <DIR>          ..
09/15/2018  11:09 AM           322,560 scp.exe
02/12/2019  03:12 AM           322,048 sftp-server.exe
09/15/2018  11:09 AM           390,144 sftp.exe
09/15/2018  11:09 AM           491,520 ssh-add.exe
09/15/2018  11:09 AM           384,512 ssh-agent.exe
09/15/2018  11:09 AM           637,952 ssh-keygen.exe
09/15/2018  11:09 AM           530,432 ssh-keyscan.exe
02/12/2019  03:12 AM           149,504 ssh-shellhost.exe
09/15/2018  11:09 AM           882,688 ssh.exe
02/12/2019  03:14 AM           974,848 sshd.exe
02/12/2019  03:12 AM             2,253 sshd_config_default
              11 File(s)      5,088,461 bytes
               2 Dir(s)  812,082,962,432 bytes free
(dev) go|c:\Windows\System32\OpenSSH> cd ..

(dev) go|c:\Windows\System32> icacls OpenSSH
OpenSSH NT SERVICE\TrustedInstaller:(F)
        NT SERVICE\TrustedInstaller:(CI)(IO)(F)
        NT AUTHORITY\SYSTEM:(M)
        NT AUTHORITY\SYSTEM:(OI)(CI)(IO)(F)
        BUILTIN\Administrators:(M)
        BUILTIN\Administrators:(OI)(CI)(IO)(F)
        BUILTIN\Users:(RX)
        BUILTIN\Users:(OI)(CI)(IO)(GR,GE)
        CREATOR OWNER:(OI)(CI)(IO)(F)
        APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES:(RX)
        APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES:(OI)(CI)(IO)(GR,GE)
        APPLICATION PACKAGE AUTHORITY\ALL RESTRICTED APPLICATION PACKAGES:(RX)
        APPLICATION PACKAGE AUTHORITY\ALL RESTRICTED APPLICATION PACKAGES:(OI)(CI)(IO)(GR,GE)

Successfully processed 1 files; Failed processing 0 files