1

It's my first time using SSH and so far I managed to connect via SSH to my Hostgator server. What I aim to do is to move files from my Hostgator account, to my Godaddy hosting account and file size is about 1Gb so FTP is out of the question since it would take forever (I tried earlier with FTP).

Now I'm trying to setup a SSH tunnel directly between my Hostgator and Godaddy so I can transfer files directly and much faster, but I'm stuck in this part.

Should I open two SSH sessions? Could you experienced geeks help move me in the right direction? I did research for a few hours and I still feel like I'm lost in this part.

4

2 回答 2

3

Use SSH connect to your Godaddy server. Then once you've done that cd to whatever directory you want the files to be copied to. Next open an sftp session to your Hostgator account using the command:

sftp -P [port-number] <address-of-hostgator-server>

The port number is the port that you use when you SSH to the server normally. If you don't usually specify a port when connecting the default is 22.

From there you can download the files to the godaddy sever using the cd command to find the files/directories you want and then the get command on the file or directory you want to download them.

Note: This will not work if the Godaddy servers have a firewall rule blocking port 22 (or whatever port you use to connect to hostgator) outbound in which case you're out of luck, you'll need to download the files locally and then upload them again.

Some Theory

To copy files from one host to another you can't copy files from SSH by itself, you need to use something like sftp or wget. In this case sftp is the easiest option because it is already installed on whatever linux host you are using and if the target server has SSH enabled you can use it.

When you SSH from your computer that you are working on to the GoDaddy server, any commands you run inside of that SSH shell are now being run on that GoDaddy server. By using the sftp command inside of this shell you create a connection between the GoDaddy server and the Hostgator server which you can control through the SSH shell you have open to GoDaddy. In essence you are using SSH to control the GoDaddy server which is using sftp to communicate with the Hostgator server.

Actually Doing It

To answer your example from the comments, you SSH to the GoDaddy server, then cd to wherever you want to the new files to go. Then once you've done that open the connection to the hostgator server using the command you proposed.

sftp -P 2222 username@my_server_ip

Now your SSH prompt should change to an sftp> prompt. This means that any commands you run now are commands for the sftp connection between the GoDaddy server and the Hostgator server. Now cd to wherever the "test" directory is on the Hostgator server and use get -r test to download that directory which will copy it to the GoDaddy server. Then type exit into the sftp prompt returning you to the SSH prompt for the GoDaddy server where you will now find your files.

于 2013-08-17T23:27:05.263 回答
0

Use ssh to connect to one of the machines. For example:

$ ssh <username>@<godaddy-server>

Then from that machine, use scp to copy files across machines. For example, to transfer the file from godaddy to your home directory on hostgator:

$ scp <file-on-godaddy> <username>@<hostgator-server>:~

The -r option can be used with scp to transfer directories. In the preceding example, the colon separates the remote machine's address from the path the file will be copied to. In the example, ~ was used to transfer to the home directory.

于 2013-08-18T00:07:12.763 回答