How to page: using command line sftp



How to: use command line sftp

The purpose of using sftp is to transfer a file or files from one machine to another. So think of the machine that you are on as "A" and the one that you are going to login to as "B". The instruction example below is simplified to get you started.
You need to know the full path of where the file is and where the file will be going. So ahead of time "cd" to each of those directories on the two machines and do a "pwd" command to get the full path.

CASE 1: Move a file from "A" over to "B". You are logged into "A".

  1. In my example, I have determined that the file I want to move, named example.txt, is in the csc1xx directory in my account on A.
  2. So I will "cd" to that directory and do a "pwd" command. The result is "/home/username/csc1xx"
  3. The place I want to put the file on "B" is my account there but in the "123files" directory.
  4. Now that I am in "/home/username/csc1xx" where my example.txt is I will type the command "sftp mysusername@machineB.union.edu"
  5. The response will be to ask for my password on "B" and login me into machine "B"
  6. I am now in my home directory and I want to put the file in "123files" so at the sftp prompt I type cd 123files That places me in "123files" on "B".
  7. Now I type put example.txt and sftp will transfer a copy of the file.
CASE 2: Move a file from "B" back to "A". You are logged into "A".
  1. Suppose there is a file on "B" that I want to bring back to a directory "hw3" I have on "A".
  2. First what I will do is to "cd" to that destination directory when I log into "A", cd hw3. A "pwd" here will return "/home/username/hw3"
  3. The file, assignment3.txt, on "B" is located in /home/cscXXXpub.
  4. Now that I am in "/home/username/hw3" where I want to put my file I will type the command "sftp mysusername@machineB.union.edu"
  5. The response will be to ask for my password on "B" and login me into machine "B"
  6. I am now in my home directory but the file I want is in /home/cscXXXpub, so at the sftp prompt I type cd /home/cscXXXpub
  7. If I now type "ls" I should see the file I want listed
  8. It's there so now I type get assignment3.txt and it comes back to "/home/username/hw3".

When the file has been transferred you can type "bye" to exit sftp.

While in sftp type "?" or "help" to see all the possible commands.
Note some commands start with "l". So "ls" is for the machine you're logged into ("B") and "lls" (local ls) is for the machine you're on "A".

[root@eagle]# sftp spallhol@antipasto.union.edu
Connecting to antipasto.union.edu...
spallhol@antipasto.union.edu's password: 
sftp> ?
Available commands:
cd path                       Change remote directory to 'path'
lcd path                      Change local 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'
help                          Display this help text
get remote-path [local-path]  Download file
lls [ls-options [path]]       Display local directory listing
ln oldpath newpath            Symlink remote file
lmkdir path                   Create local directory
lpwd                          Print local working directory
ls [path]                     Display remote directory listing
lumask umask                  Set local umask to 'umask'
mkdir path                    Create remote directory
progress                      Toggle display of progress meter
put local-path [remote-path]  Upload file
pwd                           Display remote working directory
exit                          Quit sftp
quit                          Quit sftp
rename oldpath newpath        Rename remote file
rmdir path                    Remove remote directory
rm path                       Delete remote file
symlink oldpath newpath       Symlink remote file
version                       Show SFTP version
!command                      Execute 'command' in local shell
!                             Escape to local shell
?                             Synonym for help
sftp> bye