Sun Microsystems Logo
Products and Services
 
Support and Training
 
 

Previous Previous     Contents     Index     Next Next

Examples--Copying Files to a Remote System (ftp)

In this example, the user kryten opens an ftp connection to the system pluto, and uses the put command to copy a file from his or her system to the /tmp directory on system pluto.

$ cd /tmp
ftp pluto
Connected to pluto.
220 pluto FTP server (SunOS 5.8) ready.
Name (pluto:kryten): kryten
331 Password required for kryten.
Password: xxx
230 User kryten logged in.
ftp> cd /tmp
250 CWD command successful.
ftp> put filef
200 PORT command successful.
150 ASCII data connection for filef (129.152.221.238,34356).
226 Transfer complete.
ftp> ls
200 PORT command successful.
150 ASCII data connection for /bin/ls (129.152.221.238,34357) (0 bytes).
dtdbcache_:0
filea
filef
files
ps_data
speckeysd.lock
226 ASCII Transfer complete.
60 bytes received in 0.058 seconds (1.01 Kbytes/s)
ftp> bye
221 Goodbye.

In this example, the same user kryten uses the mput command to copy a set of files from his or her home directory to pluto's /tmp directory. Note that kryten can accept or reject individual files in the set.

$ cd $HOME/testdir
$ ls
test1   test2   test3
$ ftp pluto
Connected to pluto.
220 pluto FTP server (SunOS 5.8) ready.
Name (pluto:kryten): kryten
331 Password required for kryten.
Password: xxx
230 User kryten logged in.
ftp> cd /tmp
250 CWD command successful.
ftp> mput test*
mput test1? y
200 PORT command successful.
150 ASCII data connection for test1 (129.152.221.238,34365).
226 Transfer complete.
mput test2? y
200 PORT command successful.
150 ASCII data connection for test2 (129.152.221.238,34366).
226 Transfer complete.
mput test3? y
200 PORT command successful.
150 ASCII data connection for filef (129.152.221.238,34356).
226 Transfer complete.
ftp> bye
221 Goodbye.

Remote Copying With rcp

The rcp command copies files or directories between a local and a remote system or between two remote systems. You can use this command from a remote system (after logging in with the rlogin command) or from the local system (without logging in to a remote system).

With rcp, you can perform the following remote copy operations:

  • Copy a file or directory from your system to a remote system

  • Copy a file or directory from a remote system to your local system

  • Copy a file or directory between remote systems from your local system

If you have the automounter running, you can perform these remote operations with the cp command. However, the range of cp is constrained to the virtual file system that is created by the automounter and to operations relative to a user's home directory. Because rcp performs the same operations without these constraints, this section describes only the rcp versions of these tasks.

Security Considerations for Copy Operations

To copy files or directories between systems, you must have permission to log in and copy files.


Caution! Caution - Both the cp and rcp commands can overwrite files without warning. Ensure that file names are correct before executing the command.


Specifying Source and Target

With the rcp command in the C shell, you can specify source (the file or directory you want to copy) and target (the location into which you will copy the file or directory) with either absolute or abbreviated path names.

 

Absolute Path Names

Abbreviated Path Names

From Local System

mars:/home/jones/myfile.txt

~jones/myfile.txt

After Remote Login

/home/jones/myfile.txt

~jones/myfile.txt

Absolute path names identify files or directories that are mounted on a particular system. In the previous example, the first absolute path name identifies a file (MyFile.txt) on the mars system. Abbreviated path names identify files or directories relative to a user's home directory, wherever it might reside. In the previous first example, the abbreviated path name identifies the same file, MyFile.txt, but uses "~" symbol to indicate the jones home directory:

~ = mars:/home/jones

The examples on the second line demonstrate the user of absolute and abbreviated path names after a remote login. No difference is evident for the abbreviated path name. However, because the remote login operation mounted the jones home directory onto the local system (parallel to the local user's home directory), the absolute path name no longer requires the system name mars. For more information about how a remote login operation mounts another user's home directory, see What Happens After You Log In Remotely.

The following table provides a sample of absolute and abbreviated path names that are recognized by the C shell. The sample uses the following terminology:

  • Working directory -- The directory from which the rcp command is entered. Can be remote or local.

  • Current user -- The user name under which the rcp command is entered.

Table 39-4 Allowed Syntaxes for Directory and File Names

Logged in to

Syntax

Description

Local system

.

The local working directory

 

path/filename

The path and filename in the local working directory

 

~

The current user's home directory

 

~/path/filename

The path and filename beneath the current user's home directory

 

~user

The home directory of user

 

~user/path/filename

The path and filename beneath the home directory of user

 

remote-system:path/filename

The path and filename in the remote working directory

Remote system

.

The remote working directory

 

filename

The filename in the remote working directory

 

path/filename

The path and filename in the remote working directory

 

~

The current user's home directory

 

~/path/filename

The path and filename in the current user's home directory

 

~user

The home directory of user

 

~/user/path/filename

The path and filename beneath the home directory of user

 

local-system:path/filename

The path and filename in the local working directory

Previous Previous     Contents     Index     Next Next