sftp is a program that allows the transfer of files
between two unix hosts. It is generally used interactively,
although its functions may be scripted with a shell script. All data transfer through sftp is secure; this includes the login information, so that data compromis is more difficult that without the secure functionality.
|
||||
[loriotg@gollum ~] sftp apollo
Connecting to apollo...
sftp> quit
[loriotg@gollum ~]
|
sftp apollo
command. The one argument (apollo) is the hostname of the computer to which you want to attach and transfer data to/from. In the example above, user loriotg on host gollum attached securely to host apollo. If the remote host does not recognize the user loriotg the host will request a password. In the case of LSC ATM students, all remote Linux machines will recognize the user. The user is then left with the sftp command prompt where subsequent actions such as retrieving files may be done. sftp may be terminated by entering the command
"quit".
interactive commands:
cd command. Unless the sftp host
is configured differently, you will start in the home directory of
the user that you authenticated your ftp connection with. All
cd
commands will be performed on the remote host's file system, not
the local file system. By default, sftp will download any
requested files to the current directory that the user's shell was
in when the sftp program was started. If you wish to change the
current working directory on the local machine you may use the
lcd command ("local cd"). You may use
the command ls to show a listing of the files in
the current directory on the remote host and the command lls to show a listing of the files in the current directory of the local computer.
Example sftp session below:
|
||||
[loriotg@gollum ~] pwd
/mnt/homes/loriotg
[loriotg@gollum ~] sftp apollo
Connecting to apollo...
sftp> pwd
Remote working directory: /mnt/homes/loriotg
sftp> lpwd
Local working directory: /mnt/homes/loriotg
sftp> cd test
sftp> lcd test_fortran
sftp> ls
Halo alex brookd cart examples fkink fortran ftkink
hello hello2 hosts macielj md md-ew md012 mdbnch
occomm parcfd pibal.f pingpong ring srtest stream test
testmpi
sftp> lls
dotprod dotprod_serial hello.f hello_serial.f output1 tint.f
dotprod.f dotprod_serial.f hello_mpi.f kangaroo.hosts pibal.f tint.f~
dotprod.o file hello_serial output testdp.f
sftp> help
Available commands:
bye Quit sftp
cd path Change remote directory to 'path'
chgrp grp path Change group of file 'path' to 'grp'
chmod mode path Change permissions of file 'path' to 'mode'
chown own path Change owner of file 'path' to 'own'
df [-hi] [path] Display statistics for current directory or
filesystem containing 'path'
exit Quit sftp
get [-P] remote-path [local-path] Download file
help Display this help text
lcd path Change local directory to 'path'
lls [ls-options [path]] Display local directory listing
lmkdir path Create local directory
ln oldpath newpath Symlink remote file
lpwd Print local working directory
ls [-1aflnrSt] [path] Display remote directory listing
lumask umask Set local umask to 'umask'
mkdir path Create remote directory
progress Toggle display of progress meter
put [-P] local-path [remote-path] Upload file
pwd Display remote working directory
quit Quit sftp
rename oldpath newpath Rename remote file
rm path Delete remote file
rmdir path Remove remote directory
symlink oldpath newpath Symlink remote file
version Show SFTP version
!command Execute 'command' in local shell
! Escape to local shell
? Synonym for help
sftp> quit
[loriotg@gollum ~]
|
test remote directory (on apollo) and to the test_fortran local directory (on gollum) and lists files in each directory. User then issues the help command to list all sftp commands and quits the session.
get command
will copy (get)a file from the remote host to the local host, as in the session below. Note which directory is local and which is remote.
|
||||
sftp> pwd
Remote working directory: /mnt/homes/loriotg
sftp> cd hello
sftp> pwd
Remote working directory: /mnt/homes/loriotg/hello
sftp> lcd test
sftp> lls
alex examples ftkink hello2 md md-ew pibal.f srtest testmpi
brookd fkink Halo hosts md012 occomm pingpong stream
cart fortran hello macielj mdbnch parcfd ring test
sftp> ls
hello hello.f hello.o hello_serial.f metlabhosts
sftp> get hello.f
Fetching /mnt/homes/loriotg/hello/hello.f to hello.f
/mnt/homes/loriotg/hello/hello.f 100% 1944 1.9KB/s 00:00
sftp> lls
alex examples ftkink hello2 macielj mdbnch parcfd ring test
brookd fkink Halo hello.f md md-ew pibal.f srtest testmpi
cart fortran hello hosts md012 occomm pingpong stream
sftp>
|
put command.
This will upload a file from the current local directory to
the current remote directory.
|
||||
sftp> pwd
Remote working directory: /mnt/homes/loriotg
sftp> lpwd
Local working directory: /mnt/homes/loriotg/lab10
sftp> cd test
sftp> lls
met_em.d01.2000-01-24_12:00:00.nc met_em.d01.2000-01-25_00:00:00.nc
met_em.d01.2000-01-24_18:00:00.nc met_em.d01.2000-01-25_06:00:00.nc
sftp> put met_em.d01.2000-01-24_12:00:00.nc
Uploading met_em.d01.2000-01-24_12:00:00.nc to /mnt/homes/loriotg/test/met_em.d01.2000-01-24_12:00:00.nc
met_em.d01.2000-01-24_12:00:00.nc 100% 5340KB 5.2MB/s 00:00
sftp>
|
mget and mput allow you to download or
upload files (respectively) using common unix wildcard
characters to specify what files to transfer.
|
||||
>>
[loriotg@gollum ~] sftp apollo
Connecting to apollo...
sftp> pwd
Remote working directory: /mnt/homes/loriotg
sftp> lcd lab10
sftp> lpwd
Local working directory: /mnt/homes/loriotg/lab10
sftp> mget met_em*
Fetching /mnt/homes/loriotg/met_em.d01.2000-01-24_12:00:00.nc to met_em.d01.2000-01-24_12:00:00.nc
/mnt/homes/loriotg/met_em.d01.2000-01-24_12:0 100% 5340KB 5.2MB/s 00:00
Fetching /mnt/homes/loriotg/met_em.d01.2000-01-24_18:00:00.nc to met_em.d01.2000-01-24_18:00:00.nc
/mnt/homes/loriotg/met_em.d01.2000-01-24_18:0 100% 5322KB 5.2MB/s 00:00
Fetching /mnt/homes/loriotg/met_em.d01.2000-01-25_00:00:00.nc to met_em.d01.2000-01-25_00:00:00.nc
/mnt/homes/loriotg/met_em.d01.2000-01-25_00:0 100% 5340KB 5.2MB/s 00:01
Fetching /mnt/homes/loriotg/met_em.d01.2000-01-25_06:00:00.nc to met_em.d01.2000-01-25_06:00:00.nc
/mnt/homes/loriotg/met_em.d01.2000-01-25_06:0 100% 5322KB 5.2MB/s 00:00
sftp> lls
met_em.d01.2000-01-24_12:00:00.nc met_em.d01.2000-01-25_00:00:00.nc
met_em.d01.2000-01-24_18:00:00.nc met_em.d01.2000-01-25_06:00:00.nc
sftp>
|
sftp can be setup on the remote host to allow any
user to login without a proper username or password. In this
case, the username will be "anonymous" and the
password may be anything. Typically, a connecting user would
provide their email address as the password but it is usually
not required. sftp servers do not support anonymous connections except in unusual circumstances. Downloads over web-based connections are the common methods of 'anonymous' file transfers.
scp functions similar to the unix cp
command with the difference being that you can specify remote files
or directories as the source or destination of the copy
function. scp like sftp uses the same
encryption and authentication as the ssh
command. scp can specify the remote host, username and
path to the file in the following manner:
username@host:/path/filename
"username" would be the name of the user account
on the remote machine that will be used to log onto the
remote host. "host" would be the hostname or
network address of the remote host.
"/path/filename" would be the absolute path to the
file "filename" on the remote host. A few examples
of file copies using scp are below:
|
||||
>> >> scp root@omega:/scripts/runme.sh /newscripts/ >> |
scp will log on to the
host omega as the user named root. The host and
username information is separated from the remote file and path by
the colon ":" The file specified /scripts/runme.sh
will be found on the remote host, omega, and copied from there to
the directory /newscripts.
|
||||
>> >> scp tuckerm@omega:/path/to/some/file.txt . >> |
|
||||
>>
>> scp localfile.txt tuckerm@kangaroo:/path/to/place/file/
>>
|
|
||||
>>
>> scp /absolute/path/to/file.dat tuckerm@kangaroo:
>>
|
wget is a commandline file retrieval tool that can
fetch files from ftp or web servers. It does not display the
contents of the file, it only downloads a copy of the file to the
current directory. There are many options that can modify the
behavior of wget.
|
||||
>>
>> wget http://apollo.lsc.vsc.edu/index.html
--18:33:19-- http://apollo.lsc.vsc.edu/index.html
=> `index.html'
Resolving apollo.lsc.vsc.edu... done.
Connecting to apollo.lsc.vsc.edu[155.42.21.5]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
[ <=> ] 16,843 498.43K/s
18:33:19 (498.43 KB/s) - `index.html' saved [16843]
>>
|
wget fetching files via anonymous ftp. In the case of wget anonymous filetransfer is supported on common remote hosts. However this is not as secure as sftp:
|
||||
>>
>> wget ftp.us.debian.org:/debian/README
--18:35:02-- ftp://ftp.us.debian.org//debian/README
=> `README'
Resolving ftp.us.debian.org... done.
Connecting to ftp.us.debian.org[204.152.189.120]:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD /debian ... done.
==> PORT ... done. ==> RETR README ... done.
Length: 943 (unauthoritative)
100%[==============================================================>] 943 3.18K/s ETA 00:00
18:35:14 (3.18 KB/s) - `README' saved [943]
>>
|