The aim of these pages is to give information on things that are simple to do once you know how, but a little difficult to find. Most books give information as to how to use FTP. Gnome now has a graphical ftp client, but I haven't really used it. We'll assume that you're doing this from the terminal window.
The usual command is ftp [sitename]. So, if you wanted to
download things from a site called greatlinuxstuff.com you would
type
ftp greatlinuxstuff.com
If this is a site making downloads available to the public, you
will type anonymous when asked for your login or user name and your
email as your password. You can then maneuver around the site in
the same way you would around your own hard drive, with cd, etc.
So, you've found the file you want to download. Suppose it's called
coolstuff.gz. You simply type
get coolstuff.gz
Something that wasn't as easy for me to find was how to upload
files to ones own site. However, it is also quite easy. So, let's
say that my site is called scott.com and my password is
password. I would type
ftp www.scott.com It will then ask for a user name--so, if my user
name is scott, (hmm, real original here),I type in scott. Then it
asks for password, I type password.
Now, I want to upload a new html file that I've made. Let's say
it's name is new.html So I type
put new.html
The file is then uploaded.
The only thing here is that you have to be in the directory from
which you are planning to upload your files. For example, if I'm in
/home/scott and my html file is in a directory called htmls I won't
be able to upload it. So before connecting to the ftp client, I
first cd to my html directory. So, firstly,
cd htmls
Then
ftp www.scott.com
The trouble I had was when I wanted to upload multiple files. For
example I was uploading my jpgs to a new website. I wanted to
upload all of them at once and didn't know the command. I posted
the question on the onelist Linux mailing list and quickly got
three answers, all of which work.
So, firstly I had done cd to get in my jpg folder. Then, I make
my ftp connection. The command for multiple files is
mput *.jpg
However, the trouble with that one was that I was then asked did I
want to upload a.jpg, b.jpg etc. I wanted a way around that. The
three solutions that worked were
first connect then type
prompt
Then hit enter. This turns off the prompting for each file.
The second method was when doing the ftp add the -i flag. Usually,
of course, adding -i makes it start to prompt, such as in rm -i,
but in this case, it removes the prompting mode. So, I would
type
ftp -i www.scott.com
mput *.jpg
Then, it uploaded all the jpg files in the directory without me
having to supervise the operation.
The third solution was to use, rather than ftp, ncftp. The
syntax then depends upon which version you have, but usually it is
this ncftp -u www.scott.com
If that doesn't work, then put in your user name first. So it would
be
ncftp -u scott www.scott.com
Then, you don't even need mput, the put command will work to upload
the multiple files without being questioned about each one.
put *.jpg
Brian Johnson, one of the administrators of the Egroups Linux list was kind enough to post the following list of commands:
ftp ftp.somesite.com ;connects you to the site cd ; just what it looks like :-P ls ; again, just what it looks like binary ; changes to binary mode transfers ascii ; changes to ascii mode transfers hash ; optional command, turns on progress hash marks get filename ; downloads the file put filename ; uploads a local file quit ; oh come on, you know what this does
One last little trick. If, and only if, security was no issue at all, you can also automagic the procedure. The big trouble is that it leaves your user name and password in your home directory in clear text. So, it's up to you. (Of course, .fetchmailrc does the same thing, but...) You start by creating a file called .netrc in your home directory. The layout would be as follows
machine your ftp server
login username
password password
You can also add commands to this file such as changing into your html directory, using binary, etc. First add the line
macdef init
Then, add your commands, a line at a time, for example
binary
lcd /home/user/html
One important note with this--you have to, in whatever text editor you use to create this file, follow the final command with a return--otherwise you get an error message.
Lastly, change the mode on your .netrc file
chmod 600 .netrc
The process can also be automated, although slightly differently in Windows using DOS. Make a batch file
ftp -s:textfile.txt servername.
The textfile.txt (which must be in whatever directory you are in when starting the ftp command) simply reads
username
password
It could also have any other commands that you wish to use. Most of the ones that Brian provides above will work in DOS as well.
One more note on MS's FTP. If you make a file such as
ftp -s:textfile.txt ftp.site.com and save it as ftp.bat you may or may not get, when you click on it, nothing but rapid scrolling in the DOS window. This can usually be fixed by naming the batch file something other than ftp--for example, 11ftp.bat or something like that--it has to do with MS's O/S's sometimes getting confused.
As you can see, using FTP is quite simple. Most of this information is easily available, the only reason I include this small FTP section is because my criterion is did I have to look in more than two or three places to find the answer. In this case, the uploading multiple files aspect required looking in several places, so I decided to add this little section to my pages.