SSH gives you access to a set of commands and a shell
on a remote machine. By itself, it does not enable you to copy files, it
however provides thescp command.
Say you want to copy a file called 'dumb' from the current directory of the
local machine to your home directory on a remote machine called www.foobar.com.
Your account name on the remote machine is 'bilbo'. The command would be:
scp dumb bilbo@www.foobar.com:.
To copy it back:
scp bilbo@www.foobar.com:dumb .
'scp' calls SSH to do the login, then it copies the
file and then calls SSH again to close the connection.
If your '~/.ssh/config' already contains a configuration
for your account on www.foobar.com like
Host *fbc HostName www.foobar.com User bilbo ForwardAgent yes
then you can replace 'bilbo@www.foobar.com' with 'fbc':
scp dumb fbc:.
'scp' assumes your home directory on the remote machine
to be your current working directory, so if you are using relative paths
for the remote machine, they have to be relative to the location of your
home directory on that machine.
Using the -r switch for 'scp', you can also copy directories
recursively. 'scp' also allows you to copy files between remote machines.
Now you might be tempted to try something like this:
you open an SSH connection to www.foobar.com. Once you are logged in, you
type scp [local machine]:dumb . to copy the local file 'dumb'
to the remote server you are currently logged in. Most likely you will get
a message like
ssh: secure connection to [local machine] refused
What has happened is that you executed the remote
version of 'scp', and it tried to connect to an SSH server running on your
machine ... So remember to run 'scp' always from a local terminal, unless
your machine also runs an SSH server.
section index top
If you prefer a more 'ftp-ish' approach, try 'sftp'
(part of the sftp RPM). 'sftp' establishes an SSH tunneled FTP connection
to a server and allows you to use most of the standard FTP command set. As
an added bonus, 'sftp' allows you to run remote programs via the exec
command. Since version 2.0.7, the popular graphical FTP clientgftp supports sftp-transfers, which makes
up for sftp's somewhat limited feature set.
If the remote server doesn't have the sftp server, 'sftpserv',
running, just copy the 'sftpserv' executable to your remote home directory
(or a directory you have access to and which is included in your remote $PATH).
'sftp' will activate this server automatically upon connect, you'll need
no extra permissions on the remote server.
section index top
'rsync', the immensely useful tool for copying, updating
and removing remote and local files, can most easily be used with SSH by
adding the option-e ssh . I'm using it myself for MUO ;-).
One of the advantages of 'rsync' is, that it only transfers the differences
between two given sets of files. A whole file is only transferred if it is
missing at the target location. Furthermore it offers a very efficient method
for compressing data and thus makes transfers even faster.
You'll find 'rsync' on your Mandrake CD.
section index top
If you really insist on using your traditional FTP client,
prepare for some fiddling ;-). SSH allows all kinds of protocols to be 'tunneled',
FTP too. FTP is a bit of a weird protocol however (e.g. it requires two ports)
and results may differ from server to server and from client program to client
program. If your FTP client doesn't support connecting to a specified port,
you can forget it right away.
The magic word is 'port forwarding'. You forward a non-privileged
local port (i.e. usually a port > 1000) to a remote server and then connect
to the local machine. Sounds complicated? Well, it is. And I can't
be of much help here since I haven't got to getting it working either.
The basic idea is to forward a port, fork SSH into the background and occupying
it with a senseless command to keep the channel open:
ssh [user@remote host] -f -L 1234:[remote host]:21
tail -f /etc/motd
Now start an FTP client, and point it at the forwarded
port:
lftp -u [user name] -p 1234 localhost
Whereas commands like cd are OK, commands
like ls or get either result in a hanging process
or mysterious error messages or both.
There are several programs which try to get around this
problem: ftpsshd and hsftp. But all of them are
either not working correctly or are too inconvenient to use.
Bottom line: For transferring files, better stick with
one of the first three methods.
section index top
Tunneling POP, X, VNC ...
|