How to You Upload Files Using Ssh
How to upload and download files through SSH using PuTTY (for Windows users)
In this tutorial we'll show you how to transfer files from your local reckoner to your hosting account and vice versa through SSH (Secure Shell) using PuTTY. PuTTY is an application with which Windows users can connect to their hosting accounts through SSH and execute commands, transfer files, etc. To learn more about PuTTY, where to find information technology, how to configure it and what y'all have to do to connect to your account through SSH, read the tutorial on connecting to your account through SSH (for Windows users).
In this tutorial we assume that you already have installed the whole PuTTY installation package on your local figurer and y'all know how to configure information technology to connect to your account.
As you have probably noticed the PuTTY installation package contains several other applications, besides PuTTY itself. These include Pageant, PSCP, PSFTP, etc. What you need for file transferring is either PSCP or PSFTP:
SCP (Secure Re-create) and SFTP (SSH File Transfer Protocol) are network protocols which use SSH for file transfer. When information technology comes to transferring speed, they are a flake slower than the more commonly used FTP simply they are much more secure.
PSCP and PSFTP are the PuTTY applications for transferring files over SCP and SFTP. SFTP is a newer protocol designed to work with SSH-2 (Secure Shell version 2). Despite its name, PSCP too uses SFTP as its first option for transferring files when the server to which PSCP is connected is an SSH-2 server. Practically all servers, including HostKnox servers, are SSH-2 servers.
The main divergence between PSCP and PSFTP is that PSCP is primarily used for downloading and uploading files (it can besides be used to list files in a remote directory). PSFTP is more like an FTP customer (e.grand. FileZilla), pregnant that it can exist used not just to transfer files, but also to browse the files and folders on your account, to delete them, etc. PSFTP and PSCP are, withal, command line applications. This means that they are used through the Command Prompt of your Windows operational system and y'all have to type the commands manually.
So, to starting time PSCP or PSFTP you have to get-go the Command Prompt offset. To do this, click on the Windows Start button in the lower left corner of your screen, so click on Run... and in the window that opens type cmd and click on OK. This will launch the Control Prompt from which you can get-go PSCP or PSFTP.
In order to connect to your account and transfer files you also have to commencement Pageant and add your private SSH key. For more information on this check the tutorial on connecting to your account through SSH using PuTTY.
First we'll go over PSCP and we'll evidence you how to start it and use it to transfer files from your local computer to your hosting account and vice versa. To offset information technology, you have to type a command in the Command Prompt to add together PSCP to the organization path. If, for example, you have installed all the PuTTY applications in a folder called putty on your local D bulldoze, the command should look like this: set path=%path%;d:\putty. Later you blazon it press Enter on your keyboard to execute the command.
After y'all do that yous're ready to type commands to transfer files with PSCP. To upload a file from your local computer to the public_html directory on your account (the directory where yous accept to put the files you demand for your site), you lot have to execute a control in the Command Prompt that looks like this:
pscp d:\documents\example.txt username@e.hostknox.com:/domicile/username/public_html
This command volition transfer a text file called example.txt from the documents folder on your local D bulldoze to the public_html directory on your account. Yous have to replace username in both places with your actual primary username and, if needed, the server name. The part between the @ symbol and the colon is the address of the server and the office afterwards the colon is the path to the public_html binder (/home/username/public_html).
To download a file from your business relationship to your local computer just type first the path to the file on your hosting account then the identify on your local computer where you want to download it:
pscp username@e.hostknox.com:/home/username/public_html/example.txt d:\documents
The only spaces in the pscp control are after pscp and betwixt the two paths. If you desire to upload a file which has spaces in its file proper name (or the directory containing information technology has spaces), y'all accept to put the whole path to the file on your local computer in quotation marks. The same has to be done if you download a file on your local reckoner in a directory that has spaces in its name. For instance, you lot want to upload a file chosen my example file.txt from a folder called documents on your local D drive to the public_html directory on your business relationship:
pscp "d:\documents\my example file.txt" username@e.hostknox.com:/home/username/public_html
If you want to download the same file (a file with spaces in the name) from your hosting business relationship, you merely need to put quotation marks around the file proper noun:
pscp username@due east.hostknox.com:/home/username/public_html/"my example file.txt" d:
The above command will download a file called my case file.txt from your account to the D drive on your local reckoner.
Notice besides that when yous specify the path to your account you have to use forrard slashes (/) while for the path on your local computer you take to utilize astern slashes (\).
The above commands will only work for single files. You lot can transfer multiple files by using wildcards (*). For example, the post-obit command volition download all the files (without any subdirectories) inside the documents folder from you account to the D bulldoze on your calculator:
pscp username@east.hostknox.com:/home/username/public_html/documents/* d:
If you want to transfer a directory together with all the files and subfolders in it, you have to add the option -r. For example:
pscp -r d:\documents username@e.hostknox.com:/home/username/public_html
The above command volition upload the entire documents folder with everything inside information technology from your local computer to the public_html directory on your account.
A tip that may save you some fourth dimension: by pressing the upwardly arrow key on your keyboard you tin scan through the previous commands that you lot take executed. With the left and correct arrow keys you can movement the line cursor to correct mistakes in your commands.
At present, let'due south movement to PSFTP. To start PSFTP, open up the Command Prompt and use the same control every bit with PSCP to add PSFTP to the organisation path (due east.g. set path=%path%;d:\putty). Don't forget that you also need to kickoff Pageant and add your private SSH key. After you lot execute the set path control, you lot just need to blazon psftp followed by a infinite and your principal username and the proper name of the server: e.grand. psftp username@e.hostknox.com.
This will log you in your business relationship in the directory /home/username. As well transferring files, yous tin can use Unix/Linux commands to scan and manage the files and folders on your account. For example, once you're logged in if you type just ls and press Enter you'll see a listing of the directories inside /home/username. 1 of them is the public_html directory. Y'all can open that folder and make it your electric current working directory by typing cd public_html. With cd .. you'll open the parent directory of your electric current directory. Here is a list with some useful commands:
ls - shows the content of the electric current directory
cd directoryname - changes the current working directory to the i specified (the specified directory has to be a subdirectory of the current one, otherwise y'all have to type the full path)
cd .. - go one directory upward
mkdir newfolder - creates a new directory called newfolder inside the current directory
rm filename - deletes a file with the specified proper noun (e.g. filename); the file has to be in the electric current directory or you have to blazon the full path
rmdir directoryname - deletes a directory, it has to be empty
lcd directoryname - changes the current working directory on your local reckoner to the one specified; for example, lcd d:\documents volition alter the working directory on your local figurer to the documents folder on the D drive
lpwd - displays the name of the current working directory on your local computer
Now, allow's go back to the main purpose of PSFTP: transferring files. Files can be downloaded with the get control:
get /dwelling house/username/public_html/examplefile.txt d:\documents\examplefile.txt
Yous have to supersede username with your bodily master username.
The to a higher place control volition download a file called examplefile.txt from the public_html directory on your account to a binder called documents on your local D drive. Observe that hither with the command in the in a higher place form nosotros have besides specified the name of the target file that we're going to save on the local figurer (d:\documents\examplefile.txt). This has to exist washed when you're downloading a file to a directory on your local estimator that is not your current working directory. Dissimilar PSCP, where if you don't specify a name the file will be saved with the original name, with PSFTP if you lot don't specify a name for the file the get command might non piece of work. You accept the choice whether to use the same proper noun for the target file or to apply a different one, but in both cases the content of the file volition be the same as that of the source file.
Since with PSFTP yous tin browse and modify the working directory on your account (cd control), yous don't take to type the full path to the file on your account that you want to download. Using the to a higher place instance, if you utilise the cd command (e.g. cd public_html) to make public_html the current working directory on your account, the command would look similar this:
get examplefile.txt d:\documents\examplefile.txt
The same is true for the current working directory on your local computer. If you lot change it with the lcd command to d:\documetns (lcd d:\documents) the in a higher place command would look like this:
get examplefile.txt examplefile.txt
Assuming the working directory on your account is public_html and the working directory on your local computer is d:\documents, the higher up command will download a file called examplefile.txt from the public_html directory on your account to the documents folder on your local D bulldoze. In this case you don't fifty-fifty have to blazon the name of the target file when you lot download it to the current working directory on your computer. You can just use get examplefile.txt and the file will exist downloaded in your working local directory with the same name equally the source file.
To download a directory with all its content (including subdirectories), you take to add, as with PSCP, the option -r:
get -r newfolder d:\newfolder
The higher up command will download a directory called newfolder from the current directory on your account to the D drive on your local computer. If you lot don't specify a name for the directory on you local drive (e.one thousand. become -r newfolder d:) PSFTP will download merely the contents of newfolder to your local D drive without the folder itself. So the contents of newfolder volition be scattered on your D drive. This, equally with files, is the instance when the current working directory on your local computer is not your local D drive. If the working directory on your local computer is the D drive, you can simply employ get -r newfolder. This will download non only the contents but as well the binder itself to the working directory on your figurer (D drive in this example). Again, as with files, if y'all want to you can specify a different proper name for the target directory (e.g. go -r newfolder newfolder1).
With the command mget you can download multiple files at the same time. For instance, mget examplefile1.txt examplefile2.txt will download the 2 files from the current working directory on your business relationship to the current working directory on your local reckoner. With the -r option yous tin can use mget to download multiple directories (e.g. mget -r dir1 dir2).
The PSFTP command for uploading files is put. Basically the same rules apply to this command as the ones for get. But in this case commencement you specify the file and path on your local computer and and so on your business relationship:
put d:\documents\examplefile.txt /home/username/public_html/examplefile.txt
The to a higher place command will upload a file called examplefile.txt from the documents binder on your local D drive to the public_html directory on your account. Similarly to the become control, if you are uploading a file to a directory that'due south non your electric current working directory you accept to specify not only the path on your account but likewise the proper noun with which the file will be saved.
If you're uploading the aforementioned file as in the above example just you take changed the current working directory on your local computer to d:\documents and the working directory on your account to public_html, you just need the command:
put examplefile.txt
With the put command you can also use the -r option to upload a directory together with its subdirectories and files (east.thou. put -r exampledir). Y'all can utilize mput to upload multiple files at once (e.g. mput examplefile.txt examplefile1.txt) or mput -r to upload multiple directories (e.g. mput -r exampledir exampledir1).
Some other thing useful to know is that with both commands (put and go) if the file proper name or directory name has spaces in it, you have to put quotation marks effectually the proper noun (e.k. put "my example file.txt").
Source: https://www.hostknox.com/tutorials/ssh/putty/file-transfer
0 Response to "How to You Upload Files Using Ssh"
Post a Comment