ARTICLES
Written by Raimo, 26 Apr 2010
Copy contents of local directory to web site
-module(webput).
-doc([{author, 'Joe Armstrong'},
{title, "Publish data on a web site"},
{keywords,[web,www,home,page,publish]},
{date, 981112}]).
-export([publish/5]).
publish(Host, User, Password, LocalDir, RemoteDir) ->
case ftp:open(Host) of
{ok, Pid} ->
case ftp:user(Pid, User, Password) of
ok ->
case ftp:cd(Pid, RemoteDir) of
ok ->
case file:list_dir(LocalDir) of
{ok, Files} ->
lists:foreach(fun(I) ->
publish(I, LocalDir, Pid)
end, Files);
{error, _} ->
exit({bad,local,directory, LocalDir})
end;
{error, Reason} ->
exit({cannot,cd,to,RemoteDir,reason,Reason})
end;
{error, Reason} ->
exit({cannot, login, as, User, reason, Reason})
end;
{error, Reason} ->
exit({cannot,connect,to,Host, reason, Reason})
end.
publish(File, Dir, Pid) ->
LocalFile = Dir ++ "/" ++ File,
case ftp:send(Pid, LocalFile, File) of
ok ->
ok;
{error, Reason} ->
exit({cannot,send,file,File,reason,Reason})
end.
This program uses the library module ftp to automate publication of data on a remote web site.
> webput:publish("bingo.baz.dobedo.se","jimbo23","waX2p34",
"/home/joe/html/mirror",
"/pub/acct2754/html").
ok
The above command does the following:
- FTP's to the host bingo.baz.dobedo.se
- Logs in as user jimbo23 with password waX2p34.
- Copies all the files in the local directory /home/joe/html/mirror to /pub/acct2754/html
Tags: [ small_examples ]
