Transferring Files with SFTP

What if you want to transfer files to and from the remote computer? The ssh program offers no way of copying files to the local computer's hard disk. You're limited to working within the confines of the remote machine. You could feasibly use the mail command-line program to e-mail the file to yourself, but that would hardly be the most elegant solution.

To transfer files, you need to use the sftp program. If you've ever used a shell-based ftp program, you'll feel right at home, because sftp isn't very different.

You can initiate a session by typing something similar to the following:

sftp knthomas@

The same rules as logging in with ssh apply, both in terms of formatting the login command and also confirming the encryption key if this is the first time you've logged in.

The sftp commands are fairly basic. For example, to copy a file from the remote machine, simply type this:

get filename 

This will copy the file into the directory you were in on the local machine before you started the sftp session.

By specifying a path after the filename, the file will be copied to the specified local directory:

get filename /home/knthomas/downloaded_files/

Sending files from the local machine to the remote machine is just as easy:

put filename 

By specifying a path after the filename, you can ensure the file is saved to a particular remote path.

One useful thing to remember is that any command preceded by an exclamation mark (!, called a bang in Linux-speak) is executed on the local machine as a shell command. So, if you wanted to remove a file on the local machine, you could type:

!rm -rf filename 

Simply typing a bang symbol on its own starts a shell session on the local machine, so you can perform even more tasks. When you're finished, type exit to return to the sftp program.

For a list of popular sftp commands, see Table 34-1.

Table 34-1. sftp Commands




Change the remote directory


Change the local directory


Download the specified file


List the remote directory


List the local directory


Create a directory on the remote machine


Create a directory on the local machine


Upload the specified file to the remote machine


Print the current remote directory


Delete the remote directory


Delete the remote file


Quit sftp


Execute the specified command on the local machine


Start a temporary local shell session (type exit to return to sftp)


Show a list of commands

Beginning SUSE Linux from Novice to Professional
Beginning SUSE Linux: From Novice to Professional
ISBN: 1590594584
EAN: 2147483647
Year: 2005
Pages: 293
Authors: Keir Thomas

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: