Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Работа с сетью в Delphi
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 06.11.2007, 21:22   #1
Lonix
Пользователь
 
Регистрация: 17.03.2007
Сообщений: 39
По умолчанию закачка по ftp

Добрый вечер! Кто нибудь знает как программно присоединится к FTP и закачать на него какую нибудь папку на моем комьютере?


Заранее спасибо!
Lonix вне форума Ответить с цитированием
Старый 06.11.2007, 21:34   #2
mihali4
*
Старожил
 
Регистрация: 22.11.2006
Сообщений: 9,201
По умолчанию

Сам не проверял:
Код:
Закачать локальную директорию по FTP

procedure uploadperftp;
procedure getdir(dir: string);
var
searchrec: tsearchrec;
details, nodetails: tstringlist;
k: integer;
begin
//iterate through directory given
if findfirst(dir + '*.*', faanyfile, searchrec) = 0 then
begin
repeat
//get rid of the both "dummy-directories" '.' and '..'
if (searchrec.name <> '.') and (searchrec.name <> '..') then
begin
//if we found a folder
if (searchrec.attr and fadirectory) = fadirectory then
begin
//get folder contents from ftp. one with details, one without
details := tstringlist.create;
nodetails := tstringlist.create;
ftpclient.list(details, '', true);
ftpclient.list(nodetails, '', false);
//we only want to have directories in the list (without '.' and '..')
for k := details.count - 1 downto 0 do
begin
if details.strings[k] <> '' then
begin
if (details.strings[k][1] <> 'd') or
(nodetails.strings[k] = '.') or
(nodetails.strings[k] = '..') then
begin
details.delete(k);
nodetails.delete(k);
end;
end;
end;
//if our directory does not exists on the server, create it
if nodetails.indexof(searchrec.name) = -1 then
begin
ftpclient.makedir(searchrec.name);
end;

//change into next directory on server
ftpclient.changedir(searchrec.name);
details.free;
nodetails.free;

//and also locally go into the next subfolder
getdir(dir + searchrec.name + '');

//we have to go one directory up after leaving the recursion
hochgehen
ftpclient.changedirup;
end 
else 
begin
//if it's only a file, upload it to the current directory
ftpclient.put(dir + searchrec.name, searchrec.name);
end;
end;
until findnext(searchrec) <> 0;
findclose(searchrec);
end;
end;
var
dir: string;
details, nodetails: tstringlist;
k: integer;
begin
//set some basic settings on your ftp client (tidftpclient)
with ftpclient do
begin
host := 'your_server.com'; // adjust your data here / hier gwunschte daten eintragen
username := 'your_username';
// adjust your data here
password := 'your_password';
// adjust your data here
passive := true; // adjust your data here
end;
ftpclient.connect;

//if you want to upload you data to an remote-directory, enter it below (does not matter if 'dirdir' or 'dir/dir')
dir := stringreplace('your/remote_directory', '', '/', [rfreplaceall]);
// adjust your data here

//remove first '/' if there's one
if dir <> '' then
begin
if dir[1] = '/' then delete(dir, 1, 1);

//but add a '/' at the end
if dir[length(dir)] <> '/' then dir := dir + '/';

//loop through our remote-directories
while pos('/', dir) > 0 do
begin
//get folder contents from ftp. one with details, one without
details := tstringlist.create;
nodetails := tstringlist.create;
ftpclient.list(details, '', true);
ftpclient.list(nodetails, '', false);

//we only want to have directories in the list (without '.' and '..')
for k := details.count - 1 downto 0 do
begin
if details.strings[k] <> '' then
begin
if (details.strings[k][1] <> 'd') or
(nodetails.strings[k] = '.') or
(nodetails.strings[k] = '..') then
begin
details.delete(k);
nodetails.delete(k);
end;
end;
end;

//if our directory does not exists on the server, create it
if nodetails.indexof(copy(dir, 1, pos('/', dir) - 1)) = -1 then
begin
ftpclient.makedir(copy(dir, 1, pos('/', dir) - 1));
end;

//change to our directory on server
ftpclient.changedir(copy(dir, 1, pos('/', dir) - 1));

//remove first directory from path ('your/directory/subdir/' --> 'directory/subdir/')
delete(dir, 1, pos('/', dir));
details.free;
nodetails.free;
end;
end;

//ftp client is ready in your remote-directory
//begin to upload our local directory
dir := 'c:yourlocaldirectory';
// adjust your data here
if dir[length(dir)] <> '' then dir := dir + '';
getdir(dir);
ftpclient.disconnect;
end;

Автор: marco senn 
http://tooldesign.ch/
mihali4 вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Корректная закачка файлов. Dj_smart Работа с сетью в Delphi 3 26.03.2009 16:57
http.Get закачка wordpress Alar Работа с сетью в Delphi 10 09.10.2007 20:19
закачка html-документа janifer Работа с сетью в Delphi 1 08.05.2007 19:06
закачка файлов с Ftp сервера smily Общие вопросы Delphi 1 30.11.2006 20:36