SFTP Put Directory

Enter Remote System to Copy Files (sftp)

SFTP Put Directory-The sftp command is interactive, the file transfer application with the previous program is ftp. However, sftp uses the SSH File Transfer Protocol to establish a secure connection to the server. Not all options are available with the command that the FTP system is commanded by the sftp system, but most of them are complementary.

Important sftp command

The following table lists important sftp commands.

Table 3-2 sftp Basic Commands


Command
Description
sftp remote-system
Establishes an sftp connection to a remote system..
sftp remote-system:file
Copies the named file from remote-system.
bye
Quits the sftp session.
help
Lists all sftp commands.
ls
Lists the contents of the remote working directory.
lls
Lists the contents of the local working directory.
pwd
Displays the name of the remote working directory.
cd
Changes the remote working directory.
lcd
Changes the local working directory.
mkdir
Creates a directory on the remote system.
rmdir
Deletes a directory on the remote system.
get
Copy remote working file directories to local work directories.
put
Copy files from the local work file directory to the remote work file directory
delete
Deletes a file from the remote working directory.

How to Open and Close the Sftp Connection to the Remote System

1. Open the connection to the remote system using the sftp command.
$ sftp remote-system
If the connection is successful, a confirmation message and prompt are displayed.

2. If prompted, type your password.
Password: password
If the sftp interface accepts your password, it will display a confirmation message and message (sftp>).
You can now use one of the commands provided by the sftp interface. The main commands are summarized in Table 3-2.

3. Close the Sftp connection.
sftp> bye

Example 3-2 Connecting sftp to Remote System

Sftp This session is designed to connect to a remote pluto system:


$ sftp pluto
Connecting to pluto.
Password: password
sftp>

Copy files from a remote system (sftp)

  1. Create a sftp connection.
  2. (Optional) Navigate to the directory on the local system where you want to copy the file.
    sftp> cd target-directory
  3. Switch to the source directory.
    sftp> cd source-directory
  4. Make sure you have read permission for the source file
    sftp> ls -l
  5. Use the get command to copy the files. Meta characters can be used with the get command.
    sftp> get filename 
  6. Close the Sftp connection.
    sftp> bye

Example 3-3 Copying Files from a Remote System (sftp)
In this example, the user opens the sftp connection to the pluto system and uses the get command to copy a file from the / tmp directory.

$ sftp pluto
Connecting to pluto...
Password: xxx
sftp> lcd /tmp
sftp> cd /tmp
sftp> ls
filea
files
ps_data
sftp> get filea
/tmp/filea                                100%  494     0.5KB/s   00:00
sftp> bye

Copying Files to a Remote System (sftp)

  1. Switch to the source directory on the local system. The directory where you type the sftp command is the local directory which is the source directory for this operation.
  2. Create a sftp connection.
  3. You can move to the destination directory.
    sftp> cd target-directory
  4. Make sure you have write permission to the destination directory.
    sftp> ls -l target-directory
  5. Use the put command to copy a file. Meta characters can be used with the get command.
    sftp> put filename
  6. Close the Sftp connection.
    sftp> bye
Example 3-4 Copying Files to a Remote System (sftp)
In this example, the user opens the sftp connection to the pluto system and uses the put command to copy the files from the systems to the / tmp directory on the pluto system.

$ cd /tmp
$ sftp pluto
Password: xxx
sftp> cd /tmp
sftp> put filef
uploading filef to /tmp/filef
filef                                     100%  325     0.3KB/s   00:00
sftp> ls
filea
filef
files
sftp> bye

Discussion: