Linux скопировать файл ftp

How do I copy a file over FTP using Ubuntu Linux?

I’m using Ubuntu Software Center 2.0.7, and I would like to copy a file from this machine over FTP. Can you please help me how to do it? I know in Windows I just open a Windows Explorer window and type ftp.www.mysite.com. Then it will ask for the user name and password. I would like to do the same in my Ubuntu Linux, but I don’t know how.

2 Answers 2

The easiest way to do this would be to open a terminal and use wget:

$ wget ftp://ftp.mysite.com/path/to/file 

You need to replace «path/to/file/ with the path of the file you want to download. That is, the address where the file is found on the disk. So, to get a file called file.txt that is in sub directory foo of directory bar, you would write:

$ wget ftp://ftp.mysite.com/foo/bar/file.txt 

If your ftp server requires a username and password:

$ wget ftp://username:password@ftp.mysite.com/foo/bar/file.txt 

Replacing «username» and «password» with your actual username and password. Do not include the $ in any of these commands.

GNU Wget is a free utility for non-interactive download of files from the Web. It supports HTTP, HTTPS, and FTP protocols, as well as retrieval through HTTP proxies.

You can also use ftp from the command line:

Enter your user name and password, then use put to upload the file:

ftp>put local_file remote_file 
ftp>put Downloads/List/Song.mp3 Song.mp3 

Do not include the ftp> in your command. That just indicates the ftp prompt.

Читайте также:  Условные переменные в linux

Finally, you either use a normal browser (eg firefox) or install a graphical ftp client. My personal favorite is gftp:

Oh, and you are not using Ubuntu Software Center 2.0.7. That is just Ubuntu’s software management app.

Note on terminology

When a terminal command is given, the symbol $ is used to indicate that it is a terminal command. See here for a discussion. It is not part of the actuall command. So, to tell you to run the command ls, I would write $ ls . You, however, should only type ls , without the $ .

Источник

How to Transfer Files Between Servers in Linux using SCP and FTP

Zaira Hira

Zaira Hira

How to Transfer Files Between Servers in Linux using SCP and FTP

Transferring files between machines is a very common operational task that you’ll do all the time as a developer.

Linux provides a number of utilities to transfer files. In this tutorial we will discuss FTP and SCP . Many automated scripts also deploy FTP or SCP to move files.

What is FTP?

FTP is a network protocol used for exchanging files over the network. It uses port 21. FTP enables you to access a remote system for exchanging files using the ftp command.

FTP Syntax

Here, host can either be the hostname or IP address of the remote host.

FTP Commands

FTP commands are similar to Linux commands. We’ll discuss some of these.

Command Usage
open Opens a remote connection with another computer.
get Copies a file from the remote system to the local system.
put Copies a file from the local system to a directory on the remote system.
mget Transfers multiple files from the remote system to the local system’s current directory.
mput Transfers multiple files from the local system to a directory on the remote system.
bye/quit Prepares to exit the FTP environment.
close Terminates the FTP connection.
ascii Enables file transfer mode to ASCII
binary Enables file transfer mode to binary.
Читайте также:  Linux автоматизация рутинных задач

How to Transfer Files via FTP

FTP offers two transfer modes: ASCII and Binary.

  1. ASCII stands for American Standard Code for Information Interchange. It is used to transfer plain files such as text files.
  2. Binary mode: Binary mode is used to transfer non-text files such as images.

The default transfer mode is ASCII.

Step 1 – Connect to FTP

In the example below, hostA is the remote host. You will be prompted for a username and password.

$ ftp hostA Connected to hostA. 220 hostA FTP server ready. Name (hostA:user): user 331 Password required for user. Password: password 230 User user logged in. Remote system type is LINUX. 

Once the connection is successful, you’ll notice the ftp> symbol in the beginning. Now we can run the FTP commands.

Step 2 – Choose file transfer mode

You can choose the mode (binary or ASCII) depending on your file type.

ftp> ascii 200 Type set to A.

Step 3 – Transfer files

We use the get command to transfer the file sample.txt from remote FTP server to local machine.

ftp> get sample.txt 200 PORT command successful. 150 Opening ASCII mode data connection for sample.txt (22 bytes). 226 Transfer complete. local: sample.txt remote: sample.txt 22 bytes received in 0.012 seconds (1.54 Kbytes/s)

Step 4. End the session

ftp> bye 221-You have transferred 22 bytes in 1 files. 221-Total traffic for this session was 126 bytes in 2 transfers. 221-Thank you for using the FTP service on hostA. 221 Goodbye.

How to Transfer Multiple Files via FTP

To transfer files in bulk, there are two commands: mget and mput .

You use mget to download the files, whereas you use mput to upload the files.

ftp> mget sample_file.1 sample_file.2
ftp> mput sample_file.1 sample_file.2

All the steps we just learned can be placed in an executable file and be scheduled. You can find the code for automation here.

Читайте также:  Обновление remmina linux mint

What is SCP?

SCP stands for Secure Copy. It uses SSH and port 22. The data transferred through SCP is encrypted and sniffers can’t access it. This makes SCP very secure.

  • Transfer files from local machine to remote host.
  • Transfer files from remote host to local machine.

SCP syntax

Let’s explore the syntax of SCP.

scp [FLAG] [user@]SOURCE_HOST:]/path/to/file1 [user@]DESTINATION_HOST:]/path/to/file2 
  • [FLAG] specifies the options that can be given to SCP. Here are some details about flags:
  • [user@]SOURCE_HOST is the source machine.
  • [user@]DESTINATION_HOST:] is the destination machine.

Note: To transfer files via SCP, credentials must be known and the user should have the permissions to write.

How to Transfer Files from Local Machine to Remote Host via SCP

To transfer files to a remote host, use the command below:

scp source_file.txt remote_username@10.13.13.11:/path/to/remote/directory

In the command above, source_file.txt is the file to be copied. Remote_username is the username for remote host 10.13.13.11 . After : the destination path is specified.

remote_username@10.13.13.11's password: source_file.txt 100% 0 0.0KB/s 00:00 

The file source_file.txt will now be placed in /path/to/remote/directory .

To copy directories, use the -r flag as demonstrated below.

scp -r /local/directory remote_username@10.13.13.11:/path/to/remote/directory

How to Transfer Files from Remote Host to Local Machine via SCP

To transfer files from a remote host to a local machine, use the command below:

scp remote_username@10.13.13.11:/remote/source_file.txt /path/to/local/directory

Be extra careful when transferring files as SCP overwrites the already existing files.

Wrapping up

In this tutorial, you learned how to transfer files and directories using FTP and SCP via command line.

When automated, these commands serve even greater purposes in data warehousing, ETL (Extract, Transform, Load), reporting, archiving and bulk file processing. Do give these commands a try. Let’s connect on Twitter.

Источник

Оцените статью
Adblock
detector