scp with port number specified

前端 未结 12 619
有刺的猬
有刺的猬 2021-01-29 17:03

I\'m trying to scp a file from a remote server to my local machine. Only port 80 is accessible.

I tried:

scp -p 80 username@www.myserver.com:/root/file.t         


        
相关标签:
12条回答
  • 2021-01-29 17:45

    You know what's cooler than -P? nothing

    If you use this server more than a few times, setup/create a ~/.ssh/config file with an entry like:

    Host www.myserver.com
        Port 80
    

    or

    Host myserver myserver80 short any.name.u.want yes_anything well-within-reason
        HostName www.myserver.com
        Port 80
        User username
    

    Then you can use:

    scp username@www.myserver.com:/root/file.txt .

    or

    scp short:/root/file.txt .

    You can use anything on the "Host" line with ssh, scp, rsync, git & more

    There are MANY configuration option that you can use in config files, see:

    man ssh_config

    0 讨论(0)
  • 2021-01-29 17:49

    Copying file to host: scp SourceFile remoteuser@remotehost:/directory/TargetFile

    Copying file from host: scp user@host:/directory/SourceFile TargetFile

    Copying directory recursively from host: scp -r user@host:/directory/SourceFolder TargetFolder

    NOTE: If the host is using a port other than port 22, you can specify it with the -P option: scp -P 2222 user@host:/directory/SourceFile TargetFile

    0 讨论(0)
  • 2021-01-29 17:50

    scp help tells us that port is specified by uppercase P.

    ~$ scp
    usage: scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
               [-l limit] [-o ssh_option] [-P port] [-S program]
               [[user@]host1:]file1 ... [[user@]host2:]file2
    

    Hope this helps.

    0 讨论(0)
  • 2021-01-29 17:53

    One additional hint. Place the '-P' option after the scp command, no matter whether the machine you are ssh-ing into is the second one (aka destination). Example:

    scp -P 2222 /absolute_path/source-folder/some-file user@example.com:/absolute_path/destination-folder
    
    0 讨论(0)
  • 2021-01-29 17:53

    for use another port on scp command use capital P like this

    scp -P port-number source-file/directory user@domain:/destination
    

    ya ali

    0 讨论(0)
  • 2021-01-29 17:53

    if you need copy local file to server (specify port )

    scp -P 3838 /the/source/file username@server.com:/destination/file
    
    0 讨论(0)
提交回复
热议问题