How to upload local file to server through Linux terminal

54

22

I am trying to upload local files to server by using Putty or SSH but not getting upload there.

Is there any direct method to upload file from local to server from Linux terminal without using FTP etc ?

Sanjeev Kumar Goswami

Posted 2014-12-10T06:52:20.767

Reputation: 643

SFTP is what you're looking for. – None – 2014-12-10T06:55:05.317

want to transfer my local file to server by using Linux Terminal.Suppose we used to access server by putty or ssh but not able to transfer there file by on same terminal. – None – 2014-12-10T07:11:01.897

Answers

74

Sure. Use scp (secure copy) like this:

scp [source file] [username]@[destination server]:.

Of course replace the bracketed [source file], [username] and [destination server] to match your local settings. So if the file was cool_stuff.txt and your username on the remote sever is sanjeev and the destination sever is example.com, the command would be:

scp cool_stuff.txt sanjeev@example.com:.

And the source could also be remote so you could do this to do the opposite of the above example:

scp sanjeev@example.com:cool_stuff.txt .

That command would copy the remote file cool_stuff.txt to whatever local directory you are in. And if you are doing this with multiple files, just use a wildcard (*) like you would for a normal cp command.

Also, the . just indicates the immediate directory path; such as the one you are in right at the moment you run the command or the immediate path that the remote user on the destination server has. But you could also specify a path like /this/path/right/here in the local to remote example:

scp cool_stuff.txt sanjeev@example.com:/this/path/right/here

Or the remote to local example right here:

scp sanjeev@example.com:cool_stuff.txt /this/path/right/here

Now if the remote server does not allow SSH and only SFTP, then SFTP is the way to go. But scp is very useful when you want to just toss a file and not do the whole SFTP process manually from the command line.

JakeGould

Posted 2014-12-10T06:52:20.767

Reputation: 38 217

14

When login to remote server is through ssh key, we can use below -i flag to pass our key to the server:

scp -i /path/to/.ssh/id_rsa path/to/file/myFiles.gz myServer.com:/folder/on/server

-i identity_file
Selects the file from which the identity (private key) for public key authentication is read.
This option is directly passed to ssh(1).

zx8754

Posted 2014-12-10T06:52:20.767

Reputation: 451

13

To add on to Jake’s answer, you could specify a location—instead of just .—to copy to by adding the path at the end of the URL as:

scp /path/to/file username@servername/ip:/destination/folder/

CBinyenya

Posted 2014-12-10T06:52:20.767

Reputation: 131

1FYI the space between remote host and path is an error, so you need to write this without a space! (editing this answer is not possible right now) – Sliq – 2018-03-21T04:09:55.137