715 - Secure FTP, Macintosh Command Line

Secure File Transfer Protocol (SFTP) transfers files between a mainframe computer or server and a desktop computer. Unlike FTP, SFTP provides the security of encrypted login.

This How To gives instructions for performing SFTP in UNIX using Terminal in Mac OS X. If you prefer a GUI SFTP program, you can download Fugu at the IT Download page. See How To #716 - Use Fugu for Secure File Transfer for instructions.

SFTP Commands
Start SFTP
Navigate Local Directories
Upload from the Mac to UNIX
Download from UNIX to the Mac
Quit SFTP

Remember that UNIX is case sensitive, which means lowercase and uppercase versions of the same letter are interpreted as different characters. Enter commands exactly as they are displayed.

SFTP Commands

Following are the SFTP commands used in the document:

!pwd Displays current path on the Mac (present working directory).
lcd path Changes the local directory path. Path is name of directory to move to.
!ls Lists (displays) files in present directory on the Mac.
put filename Moves a file from the Mac to the remote server.
get filename Moves a file from the remote server to the Mac.
? Displays a list of all SFTP commands.

Start SFTP

1. Click the Terminal icon in the Dock or double-click the Terminal icon in Applications> Utilities.

2. At the Terminal prompt, type, sftp NetID@ftp.unm.edu <return>

The first time you start SFTP a message similar to this will appear, You will have to accept a certificate to complete the connection.

At the prompt, Are you sure you want to continue connecting (yes/no)?, type yes and press <return>. You will then see a message similar to: Warning: Permanently added 'ftp.unm.edu' (DSA) to the list of known hosts.

3. At the password prompt, type your password and press <return>. The sftp prompt will appear: sftp>

Navigate Local Directories

Whether you plan to upload or download files, first you should understand how to navigate a directory or path. Make it a habit to keep your documents in the Documents directory (folder) in OS X. If you are working on a Macintosh in an IT pod you will have to work with the Documents directory for security reasons.

1. At the sftp prompt, type, !pwd <return> to see your location in the Macintosh directory. You will see something similar to this, /Users/istudent

2. To change to the Documents directory, at the sftp prompt, type:

lcd Documents <return>

Then type,

!pwd <return> to confirm your present directory. You will see something similar to this, /Users/istudent/Documents

Now that you are in the correct directory on the Macintosh, you can upload a file to or download a file from your UNIX account.

3. To view a list of documents in the Documents directory, at the prompt, type, !ls <return>

Upload from the Mac to UNIX

At the sftp prompt, type, put filename <return>

UNIX will not recognize filenames which include spaces, e.g., class notes. Either combine the words, (e.g., classnotes) or add a hyphen to separate the words (e.g., class-notes).

A message similar to this will appear - Uploading notes.txt to /nfs/user/istudent/class_notes.txt

A copy of the file will move from the Macintosh to your UNIX account.

Download from UNIX to the Mac

At the sftp prompt, type, get filename <return>

UNIX will not recognize filenames that include spaces, e.g., class notes. Either combine the words, (e.g., classnotes) or add an underscore to separate the words (e.g., class_notes).

A message similar to this will appear - Fetching /nfs/user/i/istudent/classnotes.text to classnotes.txt

A copy of the file will move from your UNIX account to the Macintosh.

Quit SFTP

At the sftp prompt, type quit and press <return>.