Skip to content Skip to sidebar Skip to footer

Can I Upload File to Ssh Server When I Am on It

There are multiple methods you tin employ to transfer files between your machine and Linux server, some of which we'll talk over in this article.

  • using the SCP command in SSH
  • using Netcat
  • using FTP
  • using Python's Simple HTTP Server

Using SCP (SSH)

SCP is a utility used to move files and directories securely via SSH. With the SCP command, yous tin can transfer files from your computer to your Linux server and vice versa. Every bit this utility uses SSH to move files, yous'll need the SSH credential of your server to transfer files.

SSH comes pre-installed on most Linux servers, but if not, you can install and enable it using the following steps.

Open the Ubuntu terminal and type.

$ sudo apt install -y openssh-server
$ sudo service ssh start

Upload files via SCP

Scp command follows this pattern

$ scp [Options] [Source] [Destination]

To transfer a file from your computer to a linux server, write these commands

$scp /path/of/your/local/file.ext [email protected]:/path/of/ file.ext -i key.pem

In the to a higher place command, get-go, you have to give the path of the file you want to copy from your figurer to the Linux server, then the username and IP address of the Linux server, and the path where you desire to re-create the file on the Linux server fallowing this pattern ([email protected]: path/of/remote/file.ext).

After running this command, information technology will require the countersign of the Linux server user account

Later entering the password, the file will be uploaded.

Download files via SCP

To download files from the Linux server to your figurer, you need to provide SCP with the local path of the file or directory and the path on the Linux Server where you'd want your file to exist uploaded.

$ scp [email protected]:/path/of/file.ext  /path/to/destination

After running this command, information technology will require the authentication password of the linux server. Once you have entered the password, and then the file will exist copied safely to your figurer.

SCP Command-Line Options

You can utilise different flags(known equally command-line options) in the SCP control.

-p flag is used to change the port. By default, ssh uses the 22 port, but with the -p flag, we can alter port 22 to something else, similar 2222.

$ scp -p 2222 path/of/your/local/file.ext [electronic mail protected]: path/of/file.ext

-r flag is used to copy the folder and all of its content.

$ scp -r /path/of/your/local/binder [e-mail protected]: /path/of/folder

-i flag is used to authenticating the connectedness using a cryptographic cardinal pair stored in a file instead of a username and password.

$ scp -i path/of/your/local/file.ext [email protected]: path/of/file.ext

-c flag is used to compress the data that y'all want to transfer.

$ scp -c path/of/your/local/file.ext [email protected]: path/of/file.ext

-q flag is used to suppress the non-mistake message and progress meter.

$ scp -q /path/of/your/local/file.ext [email protected]: /path/of/file.ext

Transfer Files Using Netcat

Netcat is a Linux utility used for raw tcp/ip communication, transferring files, port scanning, and network troubleshooting, etc. Information technology comes pre-installed in many Linux-based systems, and information technology is mainly used by Network Administrators.

If not already installed, you lot can install Netcat past typing the post-obit command

$ sudo apt-get install netcat

To transfer files using Netcat, you take to blazon these commands. Turn the Netcat server on listening mode on whatever port, e.m.(port 4747), and blazon the path of the file you lot want to send.

$ nc -l -p 4747 < path/of/file.ext

On the receiving host, run the following command.

$ nc sending-server.url.com 4747 > path/of/file.ext

Annotation: The server sending file will use less than sign in the control '<' while the receiving calculator will have '>' in the netcat command.

You lot can likewise transfer directories. Set the receiving host to mind on a port, e.g. (4747).

$ nc -l -p 4747 | tar -zxfv  /path/of/directory

Ship it to the receiving host listing on the port.

$ tar czvf - /path/of/directory | nc receiving-hast.url.com 4747

The directory will be transferred. To shut the connection, press CTRL+C

Transfer Files Using FTP

FTP (file transfer protocol) is used to transfer files between computers or clients and servers. It is faster than HTTP and other protocols in terms of file transfer considering it is specifically designed for this purpose. Information technology allows you to transfer multiple files and directories, and if there is any intermission in the connection during the transfer, the file volition not be lost. Instead, it will resume transferring where it got dropped.

You lot can install an FTP server like vsftpd using apt past running this command.

$ sudo apt install -y vsftpd

Later on the bundle has been installed, you lot have to start the service by typing.

$ sudo systemctl start vsftpd
$ sudo systemctl enable vsftpd

Then y'all tin can connect to the FTP server by typing the control FTP and the IP address.

It will enquire you the username and password of the FTP server. After you accept entered the username and password, you lot will be connected to your FTP server.

Y'all can list out all the contents of the server by executing this command.

Download via FTP

If yous desire to download any file from the FTP server, then you lot tin can get it past typing the command.

The file will be downloaded. Yous can also use different wildcards to download multiple files in a directory. For case ;

It will download all the files with the extension ".html" .

You can also set up a local directory for downloaded files from the FTP server by using the lcd control.

ftp> lcd  /home/user/directory-name

Upload files via FTP

To upload files on the FTP server, type the following command.

ftp> put  path/of/local/file

The file volition be uploaded to the FTP server. To upload multiple files, type commands.

Information technology will upload all the files with the extension ".html" .

Downloading  files using Python

Python has a module called 'http.server', which is used to transfer files, but with information technology, y'all can simply download files.

If you don't have the python installed, then type the following command.

$ sudo apt install -y python3

To turn on the python server, use the command.

$ sudo  python3  -chiliad  http.server 4747 #[port east.g.(4747)]

At present the python server is listening on port 4747.

Go to your web browser and type the IP address and port no. on which the python server is listening.

http://IP_Address:4747/

A page will open containing all the files and directory on the python server. You lot can get into any directory and download the files.

You tin can become into any directory and download whatsoever file.

Conclusion

SCP, Netcat, FTP, and Python are commonly used methods to transfer files. All of the to a higher place methods of transferring files and directories are fast, reliable, and used in mod days. There are a lot of other techniques as well; you tin adopt any method you prefer.

About the author

A security enthusiast who loves Terminal and Open Source. My area of expertise is Python, Linux (Debian), Bash, Penetration testing, and Firewalls. I'm built-in and raised in Wazirabad, Islamic republic of pakistan and currently doing Undergraduation from National University of Science and Engineering science (NUST). On Twitter i go by @UsamaAzad14

ellishinst1965.blogspot.com

Source: https://linuxhint.com/linux-server-file-transfer/

Enregistrer un commentaire for "Can I Upload File to Ssh Server When I Am on It"