
                            S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSK	Jr  SS	K	Jr  SS
KJr  S r\R                   " \R"                  R$                  \R"                  R&                  \R"                  R(                  5      \R*                   " S S\R,                  5      5       5       r\" 5       \l        g)zFImplements the command for copying files from and to virtual machines.    )absolute_import)division)unicode_literals)base_classes)base)
iap_tunnel)	scp_utils)	ssh_utils)ipc                      SSSS.n U $ )z(Generate detailed help for each version.FCopy files to and from Google Compute Engine virtual machines via scp.a  
*{command}* securely copies files between a virtual machine instance and your
local machine using the scp command.

This command works for Linux VMs and Windows Server 2019 and later VMs that
have [SSH enabled](https://cloud.google.com/compute/docs/connect/windows-ssh).

In order to set up a successful transfer, follow these guidelines:
*   Prefix remote file names with the virtual machine instance
    name (e.g., _example-instance_:~/_FILE_).
*   Local file names can be used as is (e.g., ~/_FILE_).
*   File names containing a colon (``:'') must be invoked by either their
    absolute path or a path that begins with ``./''.
*   When the destination of your transfer is local, all source files must be
    from the same virtual machine.
*   When the destination of your transfer is remote instead, all sources must
    be local.
*   When the destination is Windows Server, the source must be using a similar
    SSH version.

Under the covers, *scp(1)* is used to facilitate the transfer.

If the `--region` and `--network` flags are provided, then `--plain` and
`--tunnel-through-iap` are implied and any remote file names must be prefixed
with the remote IP address instead of the instance name. This is most useful for
connecting to on-prem resources.a  
To copy a remote directory, `~/narnia`, from ``example-instance'' to the
`~/wardrobe` directory of your local host, run:

  $ {command} --recurse example-instance:~/narnia ~/wardrobe

Conversely, files from your local computer can be copied to a virtual machine:

  $ {command} ~/localtest.txt ~/localtest2.txt example-instance:~/narnia

Remote Windows-based virtual machines require you to provide a path using
backslash notation:

  $ {command} ~/localtest.txt ~/localtest2.txt example-windows-instance:"C:\Users\Public"

Paths for remote Windows-based virtual machines which contain spaces in
directory name should be appropriately protected with a pair of nested single
and double quotes:

  $ {command} ~/localtest.txt 'example-windows-instance:"C:\Users\Public\Test Folder"'

If the zone cannot be determined, you will be prompted for it.  Use the
`--zone` flag to avoid being prompted:

  $ {command} --recurse example-instance:~/narnia ~/wardrobe --zone=us-central1-a

To specify the project, zone, and recurse all together, run:

  $ {command} --project="my-gcp-project" --zone="us-east1-b" --recurse ~/foo-folder/ gcp-instance-name:~/

You can limit the allowed time to ssh. For example, to allow a key to be used
through 2019:

  $ {command} --recurse example-instance:~/narnia ~/wardrobe --ssh-key-expiration="2020-01-01T00:00:00:00Z"

Or alternatively, allow access for the next two minutes:

  $ {command} --recurse example-instance:~/narnia ~/wardrobe --ssh-key-expire-after=2m

To use the IP address of your remote VM (eg, for on-prem), you must also specify
the `--region` and `--network` flags:

  $ {command} 10.1.2.3:~/narnia ~/wardrobe --region=us-central1 --network=default
)briefDESCRIPTIONEXAMPLES )detailed_helps    lib/surface/compute/scp.py_DetailedHelpr      s"    ,$6+?K-Z 
    c                   F    \ rS rSrSr\R                  r\S 5       r	S r
Srg)Scpo   r   c                    [         R                  R                  U5        UR                  SSS9  UR                  SSSS9  UR                  SSS	S9  UR                  S
SSS9  [        R
                  " U5        UR                  5       nUR                  SSSSS9  [        R                  " X5        [        R                  " U5        g)zPSet up arguments for this command.

Args:
  parser: An argparse.ArgumentParser.
z--portzThe port to connect to.)helpz	--recurse
store_truezUpload directories recursively.)actionr   z
--compresszEnable compression.z
--scp-flagappendz8Extra flag to be sent to scp. This flag may be repeated.z--internal-ipFad          Connect to instances using their internal IP addresses rather than their
        external IP addresses. Use this to connect from one instance to another
        on the same VPC network, over a VPN connection, or between two peered
        VPC networks.

        For this connection to work, you must configure your networks and
        firewall to allow SSH connections to the internal IP address of
        the instance to which you want to connect.

        To learn how to use this flag, see
        [](https://cloud.google.com/compute/docs/instances/connecting-advanced#sshbetweeninstances).
        )defaultr   r   N)
r	   BaseScpHelperArgsadd_argumentr
   AddVerifyInternalIpArgadd_mutually_exclusive_groupr   AddSshTunnelArgsAddHostBasedTunnelArgs)clsparserrouting_groups      r   r    Scp.Argsw   s       (
'@A
.  0
 \0E  G G  I
 $$V,779M	  $ 6%%f-r   c                 P   UR                  S5      =(       a    UR                  S5      nU(       a  SUl        UR                  (       a  [        R                  R
                  nO[        R                  R                  n[        R                  " U R                  5       5      n[        R                  " 5       n/ nUR                  (       a  UR                  UR                  5        UR                  UUUUR                  UR                   UR"                  UU R                  5       US9	$ )z!See scp_utils.BaseScpCommand.Run.networkregionT)on_premport	recursivecompressextra_flagsrelease_trackip_type)IsSpecifiedplaininternal_ipr   
IpTypeEnumINTERNALEXTERNALr   ComputeApiHolderReleaseTrackr	   r   scp_flagextendRunScpr.   recurser0   )selfargsr-   r3   holder
scp_helperr1   s          r   RunScp.Run   s     	*It/?/?/IGdj&&g&&g**4+<+<+>?F((*JK }}'YY,,'')  	 	r   r   N)__name__
__module____qualname____firstlineno____doc__r   TOOLS_CATEGORYcategoryclassmethodr    rD   __static_attributes__r   r   r   r   r   o   s+     O  (-. -.^r   r   N)rJ   
__future__r   r   r   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer   r	   r
   #googlecloudsdk.command_lib.util.sshr   r   ReleaseTracksr;   ALPHABETAGADefaultUniverseOnlyCommandr   r   r   r   r   <module>rZ      s    M &  ' 7 ( 9 8 8 2Od D%%++T->->-C-C%%((*S$,, S *Sl "O r   