Linux scp to ftp

SSH / TransferFiles

Another important function of SSH is allowing secure file transfer using SCP and SFTP.

Secure Copy (scp)

Just as all modern Unix-like systems have an SSH client, they also have SCP and SFTP clients. To copy a file from your computer to another computer with ssh, go to a command-line and type:

For example, to copy your TPS Reports to Joe’s Desktop:

scp "TPS Reports.odw" joe@laptop:Desktop/

This will copy TPS Reports.odw to /home/joe/Desktop, because SCP uses your home folder as the destination unless the destination folder begins with a ‘/’.

To copy the pictures from your holiday to your website, you could do:

scp -r /media/disk/summer_pics/ mike@192.168.1.1:"/var/www/Summer 2008/"

The -r (recursive) option means to copy the whole folder and any sub-folders. You can also copy files the other way:

scp -r catbert@192.168.1.103:/home/catbert/evil_plans/ .

The ‘.’ means to copy the file to the current directory. Alternatively, you could use secret_plans instead of ‘.’, and the folder would be renamed.

Secure FTP (sftp)

Finally, if you want to look around the remote machine and copy files interactively, you can use SFTP:

This will start an SFTP session that you can use to interactively move files between computers.

SSHFS

SSHFS is a recent addition to Linux that allows you to make a remote filesystem available over SSH act as if it was inside a folder on your own system. See SSHFS for details.

GNOME

Click File -> Connect to Server. Select SSH for Service Type, write the name or IP address of the computer you’re connecting to in Server. Click Add Bookmark if you want to make the connection available later in the Places sidebar. There are options to login as a different User Name, on a different Port number, and use a different default Folder.

Files can be copied by dragging and dropping between this window and other windows.

KDE

Open Konqueror, and in the address bar type:

fish://username@server_address

Files can be copied by dragging and dropping them between this window or tab and to other windows or tabs.

Using other programs

SecPanel and PuTTY also have file transfer utilities, although they’re generally not as easy to use as the ones discussed above.

SSH/TransferFiles (последним исправлял пользователь c-71-237-198-100 2015-01-16 00:19:38)

The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details

Источник

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 usb device port

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.

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.

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.
Читайте также:  Alt linux version kernel

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.

Источник

How to securely copy files between Linux hosts using SCP and SFTP

There are multiple methods you can use to securely copy files between Linux hosts. SCP and SFTP are two you need to know.

Two windows with a small pane open

Recently, we looked at the rsync command for syncing files between locations, and we discussed the similarity of usage and syntax when duplicating files and directories with the cp command. In that article, we looked at moving the bits back and forth on the same box, between filesystems, or between devices. In an upcoming article, we’ll look more at rsync as a tool to keep remote filesystems in sync with a local or backup version. In this article, I want to take a look at one of the most useful and used tools in the Linux sysadmin toolbox—the scp command.

What is SCP?

Linux security

Secure Copy, or scp , is a secure version of the older rcp tool (which is still used, but less common) included in the OpenSSH suite of tools.

OpenSSH started as a BSD fork of the original SSH secure communications protocol, which has since become re-licensed as «non-free» and thus not generally available for Linux. OpenSSH is still maintained under the BSD license and is available for a wide range of platforms. It includes several common tools for secure remote access, including key generation, scp , and sftp (a secure version of FTP, which we’ll get to in a bit).

Recently, OpenSSH developers have indicated that they consider scp to be deprecated (they believe it is «Outdated, inflexible and not easily fixed»). It is unclear when it will cease to be available in future releases of OpenSSH, though it’s hard to imagine that it will be dropped anytime soon.

Use SCP

The usefulness of scp lies in its simplicity. I use it to quickly move files to a remote filesystem from the shell:

skipworthy ~ scp ./enable/foo/testfoo showme:/home/skipworthy/enable skipworthy@showme's password: testfoo 100% 25 8.0KB/s 00:00

Easy as pie. I can get a file from a remote location, too:

skipworthy ~ scp showme:/home/skipworthy/enable/demofoo ~/enable/ skipworthy@showme's password: demofoo 100% 0 0.0KB/s 00:00 skipworthy ~ ls ./enable bar demofoo foo

The available connection options are the same as with ssh . For example:

skipworthy ~ scp -P 2020 -i ~/.ssh/id_rsa ./test.txt showme:/home/skipworthy/enable/ test.txt 100% 0 0.0KB/s 00:00 

-P specifies the port for the ssh connection, -i specifies an ssh id key to use for authentication: Both these options are useful for scripts. Note that the scp -P differs from the ssh -p for specifying the port. In the example above, I set the location of an ssh key ( ~/.ssh/id_rsa )—which I also generated using the OpenSSH toolkit—to authenticate access to the remote device. Learn about SSH file copies here.

Читайте также:  Драйвера сетевой карты intel linux

So you can see scp is a really useful tool to have at your fingertips. There is some discussion of the wisdom of using this tool in a secure environment, so YMMV. I’d suggest doing some reading and deciding for yourself.

Alternatives

What if, for whatever reason, we can’t use scp ? I recommend two other options that are pretty easy to use: rsync , which we have talked about here and will discuss in more depth in another article, and sftp . While neither of these options is as convenient as scp , both have some useful features.

sftp is pretty much what it sounds like: Secure FTP. It acts like FTP over an SSH-managed connection. While it’s not as simple to use as the «one and done» scp command, it offers a range of more sophisticated filesystem options and the ability to connect to a remote filesystem interactively. It does require that the target filesystem be configured for sftp access.

Let’s connect to an sftp server interactively:

skipworthy ~ sftp enable@ganymede enable@ganymede's password: Connected to ganymede. sftp> pwd Remote working directory: /upload sftp> mkdir test sftp> ls -al drwxr-xr-x 3 1002 1002 18 Nov 24 21:53 . drwxr-xr-x 3 0 1002 20 Nov 24 21:33 .. drwxr-xr-x 2 1002 1002 6 Nov 24 21:53 test

If we hit Tab twice, we can see a list of commands available at the shell:

sftp> bye cd chdir chgrp chmod chown df dir exit get help lcd lchdir lls lmkdir ln lpwd ls lumask mkdir mget mput progress put pwd quit reget rename reput rm rmdir symlink version ! ? 

So you can see it’s possible to interact with the remote filesystem. Again, the main disadvantages are the target has to be configured for sftp access and access to a specific directory has to be configured and limited by the admin of that system. This makes it a more secure, if less convenient, option than scp . Also, note that while it’s not really possible to do impromptu file transfers like scp , it is possible to write scripts and insert shell aliases to make this work more smoothly if that’s your jam.

Wrap up

Final note: Both these tools rely on the SSH toolbox, which is a very important part of Linux systems administration, so I highly recommend getting comfortable with it. Consider these excellent articles by Enable Sysadmin writers:

Источник

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