SFTP Using Command Line (UNIX, Mac OS X)
This page contains instructions on how to transfer files between two computers connected to the Internet using the SFTP utility in UNIX. This utility allows you to transfer both ASCII and binary files between computers quickly and efficiently.
Before you can perform any action using the SFTP utility, you must connect and log in to the remote host (the computer or server you wish to transfer files to or from).
To log in to the remote host:
- Bring up a UNIX prompt and type sftp USC username@usc-host.
- Use your USC username and password to log in to the remote host. The sftp> prompt displays.
Issuing Commands on the Remote and Local Hosts
Use standard file and directory UNIX commands at the sftp> prompt. For example, on the remote host, you can use ls to get a listing of the current directory, ls -l to get a long listing, or cd to move to a different directory.
To issue commands on the local host (your computer), use standard file and directory UNIX commands as when you are issuing commands on the remote host. However, you will need to begin each command with an exclamation mark (!). Your starting local or working directory is specified as the default incoming and outgoing directory.
If you want to receive files in, or send files from, a directory other than your starting working directory, you will need to specify the directory. For example, if you want to download all files to a folder called INCOMING on your local directory, you first have to create that folder with the ! mkdir UNIX command, and then you need to use the lcd command to change to that new folder. Here is the syntax for this example:
- sftp> ! mkdir INCOMING
- sftp> ! lcd INCOMING
For a more detailed explanation of other UNIX commands, visit UNIX Commands and Utilities.
Using Command Line for SFTP
To download a file from a remote host:
- Once you are pointing to the correct directory on the remote host, use the get command to copy a file to the local directory (on your computer).
- Type get filename at the sftp> prompt, and then press Enter.
- The file is copied to your local directory.
To upload a file to a remote host:
- Once you are pointing to the correct directory on the remote host, use the put command to copy a file from the local directory (on your computer).
- Type put local-path-to-file remote-path at the sftp> prompt, and then press Enter.
- The file is copied to the remote host.
To quit SFTP:
- At the sftp> prompt, type quit.
- The connection closes, and you return to the UNIX prompt.
To get help:
- At the sftp> prompt, type ?. A list of all available commands will display.
- At the sftp> prompt type ? <command>. This will return brief information on that particular command.
If you have SFTP-related questions, please call the Customer Support Center at 213-740-5555 or email firstname.lastname@example.org.