|
Warning: You must use a secure ftp client such as
SSH or MacSSH to use command line ftp.
Sometimes your ftp client isn't available to you
and you just need to do a quick file upload to your
server. Most computers will have some type of command
line program available for you to do this. (Note:
the exception is a pre-OS X Mac will not have
a command line tool). On a Unix or OS X Mac computer,
the application to run is simply called MacSSH. On
Windows, use SSH. So start up your clients, and use
these commands to upload or download files.
New Definition: root directory. The root directory,
or commonly referred to as just "root" is
the directory at the top of the hierarchy that all
other directories fall under.
Once you are into your SFTP session, you can not
select a directory to upload from or download to.
You will be stuck with the last directory you were
in when you opened your SFTP session. To change the
directory, the command is cd <dirname>. To get
to a directory called files that is one level below
root, the command would be: cd files
Open your connection, the command for this is simply,
open <server>, where <server> is where
you want to connect. So to connect to the Brown web
server, you would type: open webpub.brown.edu
If the server is available, you will be prompted
for your username. It might not be echoed back on
the screen, so you may not see your username as you
type. Hit enter. You will then be prompted for your
password. This will not be echoed back to the screen,
nor will you see dots or asterisks. The screen will
look like it isn't capturing the information, but
it is. Type your password correctly, and hit enter.
You're in.
Next is to get to the directory where you will want
to upload files to or download them from. This process
is the same as above, with the cd command, but the
first things you may want to do include finding out
what directory you're in on the server, and what other
directories you have the option to get to. To see
what directory you're in on the server, type pwd (present
working directory). The full path will be shown. To
see what other files or directories are in that directory,
type ls (list). Now that you know what your options
are for changing directories, you can get to the files
or directory needed.
Once you get to your target directory, and you finally
want to upload a file, the command for this is:
put <filename>
where if you want to upload your index page, you would
type: put index.html
Remember, we initially went to the directory that
the file was in, so now we don't easily have the option
to select a file from a directory other than the one
we started in.
To download a file, the command is: get <filename>
If you want to download a copy of your index page,
type: get index.html and it will put it into the directory
that you started from before you started the sftp.
When you're done with your sftp session, the disconnect
command is simply: bye. To close the entire window
completely, type: exit.
Binary vs. ASCII
One thing that graphical SFTP clients do really well,
is determine the file type that is being uploaded
or downloaded and open the appropriate connections.
Some files are in ASCII format, which basically means
that it is a text file, such as web pages. Other files
are in binary format, such as images or .htaccess
files. When using command line sftp, the default setting
is ASCII. To make sure binary files get transferred
properly, you will need to change this setting before
transferring. Before transferring a binary file, at
the command line, simply type: bin. To get back to
ASCII, type ascii.
Other Tips
A few other interesting characters that can be used
when changing directories with the cd command are
the / and .. (two periods). Earlier, we defined "root".
If you need to change directories all the way back
to the root directory, or want to get to a different
directory under root, use the / character. For example,
if my pwd is /export/home/jcarberry/www and I want
to quickly get to the first directory listed, I would
type: cd /export
To go backward one directory, use the .. So, if the
pwd is /export/home/jcarberry/www and I want to get
to the jcarberry directory, I would type: cd ..
That's about it, happy SFTPing!
|