Please
visit the "Unix Intro" page if you need to learn more
about unix commands. Of particular interest are the sections on
the files (listing them, using
wildcards); the path (which explains
how to move from one directory to another), and on "copying,
moving and removing files and
directories". You may also
want to visit the file transfer page
for instructiions on moving files between particular machines at
UMC or between UMC and campus.
Index
Telnet
Telnet
allows you to login, albeit insecurely, to any remote machine running
a telnet server. Telnet will
allow you to open a shell and use simple command line unix tools
on the remote machine.
>telnet
fred
In
this example, imagine you are telnetting to a machine named "fred".
Sometimes you may have to use the fully qualified name of the machine
(e.g., Fred.arizona.edu) or use Fred's IP address: 128.196.99.1.
You will need to login to Fred and provide your password.
Ftp
FTP
is the file transfer protocol. Like telnet, it is an old insecure
protocol. It is being replaced by scp, but is still in use on some
machines. FTP can operate in text or binary mode, with the prompt
on or off. It can get files from the remote machine or put files
on the remote machine, either singly or in large batches. By default,
ftp operates in text mode with the prompt on, we usually alter these
defaults at the beginning of a new ftp session. FTP will allow you
to cd between directories, but it may have trouble with listing,
copying, moving and removing files and directories. Telnet is better
suited for these general unix commands.
See
also transfer (special techniques
for transferring images back to the console)
To
start an ftp connection from a unix machine:
>ftp
Fred
As
with telnet above, you may sometimes need to use Fred's fully qualified
domain name or IP address and you will need to login.
ftp>bin
(this will tell ftp to transfer the data in binary mode instead
of text mode. You will typically be tranferring image data, so you
want to be in binary mode. In fact, it never hurts to be in binary
mode, even if you are transferring text files.)
ftp>prompt
(this will tell ftp not to ask you about transferring each individual
file. If you are about to move dozens of files, you will want to
type "prompt").
If
you are having file permission problems, you can apply the umask
command for your ftp session:
ftp>site
umask 000
Will
give everyone permission to do anything with the files and directories
on the remote machine.
Local
and Remote Machines (Understanding get and put)
In
the simplest scenario, I sit down at one machine (e.g., "Mary")
and I ftp to another machine (e.g., "Fred"):
>ftp
Fred
In
this case, Mary is my local machine and Fred is the remote machine.
However,
it can be much more complicated. Suppose I'm sitting at home at
my PC and I telnet to Mary. After logging in to Mary, I ftp Fred.
Again, Mary is the local machine (the machine where I started the
ftp session) and Fred is the remote machine.
Let's
make it even worse. I telnet from home to Mary. Then I telnet from
Mary to Fred, and then ftp from Fred to Mary. Now Fred is the local
machine and Mary is the remote machine.
To
understand when to use "get" or "mget" versus
"put" or "mput", you must understand these abstract
concepts of the remote and local machines. However, it does get
confusing, so if you try "put" and get back a message
like "no such file or directory", then try "get"
instead.
Let's
go back to the simplest case, I ftp from Mary to Fred. Mary is my
local machine.
- I
should use "put" or "mput" to transfer files
from Mary (local) to Fred (remote).
- I
should use "get" or "mget" to transfer files
from Fred (remote) to Mary (local).
You
should start your ftp session in the directory on the local machine
where files to transfer reside or where you intend to place them.
You
can use the "cd" command to move around on the remote
machine once you have ftp'd there
ftp>cd
/data/tmp
Examples
ftp>put
P01000
In
this example "put" is used to copy a single specified
file from the local machine (specifically, from the directory you
started the ftp session in) to the remote machine (the directory
you are in on the remote machine).
ftp>mput
P*
"mput"
[multiple puts] tells ftp to copy all files that meet the criterion,
in this case, all files beginning with a capital P, from the current
directory on the local machine to the current directory on the remote
machine.
ftp>get
bird.jpg
Copy
a single file "bird.jpg" from the current directory on
the remote machine to the current directory on the local machine.
ftp>mget
*.jpg
Copy
all "*.jpg" files from the current directory on the remote
machine to the current directory on the local machine.
ftp>bye
Exits
the ftp session
>man
ftp
Tells
you more about the options and flags available with ftp.
SSH
ssh=secure
shell (secure telnet)
To
use these programs, they must be installed on both communicating
machines. For a machine to receive an ssh or scp request (i.e.,
for it to answer when you request a connection to it) it must be
running an ssh server (sshd).
Typically unix machines will run ssh/scp servers (though ssh servers
can be run on Windows 2000 and XP Professional using Cygwin based
tools. If you have trouble connecting to a machine with ssh, you should
check to see if it is running an ssh server (or daemon):
>which
sshd
>ps
-ef | sshd
Same
user on local and remote machines
The
commands you are most likely to need:
ssh
machinename (where the name of the machine or IP address is substituted
for the term "machinename"), e.g.,
>ssh
buddy
ssh
assumes you want to be the same user on the machine you are sshing
TO
as
you are on the machine you are coming FROM. This can be annoying.
Different
user on local and remote machines
If
you want to login as a different user, use the following scheme:
ssh
-l username machinename
e.g.
>ssh
-l joe buddy
or
>ssh
-l joe buddy.psych.arizona.edu
(-l
= "login as")
You
will be asked for the password.
SCP
same
user on local and remote machines
scp=secure
copy (secure binary mode ftp)
Typically
unix machines will run ssh/scp servers (though ssh servers can be
run on Windows 2000 and XP Professional using Cygwin based tools.
See http://lexa.mckenna.edu/sshwindows/.
Unix:
You can use scp at the command line whether or not have used ssh
to connect to another machine.
Windows
PC: If you are using the university ssh and scp on a Windows PC,
then you have a separate scp program as well as being able to use
scp at the command line once you have connected with ssh.
SCP
move files to or from your current location. It always uses binary
mode. You can work as either the current user on the starting machine
or a different user. It always asks for the user's password. Here
are some examples in which I move the file bird.jpg from one place
to another. The first three examples assume you are the same user
on the local and remote machines. The last example shows you how
to login as someone else on the remote machine:
Put
a file on a remote machine:
>scp
bird.jpg buddy:/data/joe/
Get
a file from a remote machine:
>scp
buddy:/data/joe/bird.jpg .
(the "." means "here")
>scp
buddy:/data/joe/bird.jpg /home/fred/
(does
the same thing, but just substitutes the path for ".")
You
can scp -r so that an entire directory can be copied at a time:
>scp
-r e12345 buddy:/data/joe
different
user on local and remote machines
Log
in as someone other than who you are locally, then copy a file from
your current directory to a directory (/data/fred/) on the remote
machine:
>scp
bird.jpg joe@buddy:/data/fred
(you
will be asked for joe's password)
Copy
a file (bird.jpg) from a directory (/data/fred/) on a remote machine
(buddy) where you will login as someone else (joe) to here (.)
>scp
joe@buddy:/data/fred/bird.jpg .
Note:
A couple of people have pointed out that this last form of the scp
command does NOT
seem to work with mrisun as the remote machine. Use the preceding
form of the scp command instead.
|