Форум: "Сети";
Текущий архив: 2004.04.18;
Скачать: [xml.tar.bz2];
ВнизСоздать список фаилов на FTP сервере при помощи NMFTP Найти похожие ветки
← →
ALEKCEY (2004-02-11 20:01) [0]Как создать список фаилов на FTP сервере при помощи NMFTP и поместить его в listbox или memo.
Если можно то с конкретным кодом.
Всем заранее спасибо.
← →
gavrila © (2004-02-11 20:32) [1]Вот пример, когда пробовал, должен работать, а вообще я его в хелпе нашел
привожу по частям, т.к. макс. символов = 7168
Часть1
unit FTPExample;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids, ComCtrls, Psock, NMFtp;
type
TForm1 = class(TForm)
FTPHost: TEdit;
Label1: TLabel;
Label2: TLabel;
FTPLogin: TEdit;
FTPPassword: TEdit;
Label3: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Button10: TButton;
Memo1: TMemo;
Label4: TLabel;
StringGrid1: TStringGrid;
Label5: TLabel;
StatusBar1: TStatusBar;
NMFTP1: TNMFTP;
Button11: TButton;
OpenDialog1: TOpenDialog;
Button12: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure NMFTP1AuthenticationFailed(var Handled: Boolean);
procedure NMFTP1AuthenticationNeeded(var Handled: Boolean);
procedure NMFTP1Connect(Sender: TObject);
procedure NMFTP1Disconnect(Sender: TObject);
procedure NMFTP1Failure(var Handled: Boolean; Trans_Type: TCmdType);
procedure NMFTP1PacketRecvd(Sender: TObject);
procedure NMFTP1PacketSent(Sender: TObject);
procedure NMFTP1TransactionStart(Sender: TObject);
procedure NMFTP1TransactionStop(Sender: TObject);
procedure NMFTP1Success(Trans_Type: TCmdType);
procedure NMFTP1UnSupportedFunction(Trans_Type: TCmdType);
procedure Button11Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1 : TForm1;
implementation
{$R *.DFM}
var
GetPut : String;
procedure TForm1.Button1Click(Sender: TObject);
begin
If NMFTP1.Connected Then
Begin
NMFTP1.Disconnect;
// Button1.Caption:= "Connect";
End
Else
Begin
NMFTP1.Vendor := NMOS_Auto;
NMFTP1.Host := FTPHost.text;
NMFTP1.UserID := FTPLogin.text;
NMFTP1.Password := FTPPassword.text;
NMFTP1.Connect;
// Button1.Caption:= "Disconnect";
End;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
NMFTP1.List;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
TheDir: String;
begin
if InputQuery("Change Directory", "Which directory?", TheDir) then
NMFTP1.ChangeDir(TheDir);
end;
procedure TForm1.Button4Click(Sender: TObject);
var
TheDir: String;
begin
if InputQuery("Create Directory", "Directory name?", TheDir) then
NMFTP1.MakeDirectory(TheDir);
end;
procedure TForm1.Button5Click(Sender: TObject);
var
TheDir: String;
begin
if InputQuery("Remove Directory", "Directory name?", TheDir) then
NMFTP1.RemoveDir(TheDir);
end;
procedure TForm1.Button6Click(Sender: TObject);
var
TheFile: String;
begin
if InputQuery("Delete File", "File name?", TheFile) then
NMFTP1.Delete(TheFile);
end;
procedure TForm1.Button7Click(Sender: TObject);
var
OldFile,
NewFile: String;
begin
if InputQuery("Rename file", "File to rename?", OldFile) then
if InputQuery("Rename file", "New file name?", NewFile) then
NMFTP1.Rename(OldFile, NewFile);
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
ShowMessage("After reinitilizing, you must click the authenticate button");
NMFTP1.Reinitialize;
end;
procedure TForm1.Button9Click(Sender: TObject);
var
AnID,
APass: String;
begin
if InputQuery("Authentication needed", "Enter User ID", AnID) then
if InputQuery("Authentication needed", "Enter Password", APass) then
begin
NMFTP1.DoCommand("USER "+AnID);
NMFTP1.DoCommand("PASS "+APass);
end;
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
ShowMessage(NMFTP1.CurrentDir);
end;
procedure TForm1.NMFTP1AuthenticationFailed(var Handled: Boolean);
var
ThePass,
TheID: String;
begin
if MessageDlg("Authentication Failed. Retry?", mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
ThePass := NMFTP1.Password;
TheID := NMFTP1.UserID;
InputQuery("Reauthenticate", "Enter User ID", TheID);
InputQuery("Reauthenticate", "Enter Password", ThePass);
NMFTP1.Password := ThePass;
NMFTP1.UserID := TheID;
Handled := TRUE;
end;
end;
← →
gavrila © (2004-02-11 20:33) [2]Часть 2
procedure TForm1.NMFTP1AuthenticationNeeded(var Handled: Boolean);
var
APass,
AnID: String;
begin
if NMFTP1.Password = "" then
begin
if InputQuery("Password needed", "Enter password: ", APass) then
begin
NMFTP1.Password := APass;
Handled := TRUE;
end
else
Handled := FALSE;
end;
if NMFTP1.UserID = "" then
begin
if InputQuery("User ID needed", "Enter User ID: ", AnID) then
begin
NMFTP1.UserID := AnID;
Handled := TRUE;
end
else
Handled := FALSE;
end;
end;
procedure TForm1.NMFTP1Connect(Sender: TObject);
begin
Memo1.Lines.Add("Connected");
Button1.Caption := "Disconnect";
end;
procedure TForm1.NMFTP1Disconnect(Sender: TObject);
begin
Memo1.Lines.Add("Disconnected");
Button1.Caption := "Connect";
end;
procedure TForm1.NMFTP1Failure(var Handled: Boolean; Trans_Type: TCmdType);
begin
case Trans_Type of
cmdChangeDir: Memo1.Lines.Add("ChangeDir failed");
cmdMakeDir: Memo1.Lines.Add("MakeDir failed");
cmdDelete: Memo1.Lines.Add("Delete failed");
cmdRemoveDir: Memo1.Lines.Add("RemoveDir failed");
cmdList: Memo1.Lines.Add("List failed");
cmdRename: Memo1.Lines.Add("Rename failed");
cmdUpRestore: Memo1.Lines.Add("UploadRestore failed");
cmdDownRestore: Memo1.Lines.Add("DownloadRestore failed");
cmdDownload: Memo1.Lines.Add("Download failed");
cmdUpload: Memo1.Lines.Add("Upload failed");
cmdAppend: Memo1.Lines.Add("UploadAppend failed");
cmdReInit: Memo1.Lines.Add("Reinitialize failed");
cmdAllocate: Memo1.Lines.Add("Allocate failed");
cmdNList: Memo1.Lines.Add("NList failed");
cmdDoCommand: Memo1.Lines.Add("DoCommand failed");
cmdCurrentDir: Memo1.Lines.Add("CurrentDir failed");
end;
end;
procedure TForm1.NMFTP1PacketRecvd(Sender: TObject);
begin
StatusBar1.SimpleText := "Received "+IntToStr(NMFTP1.BytesRecvd)+" bytes of "+IntToStr(NMFTP1.BytesTotal)+" total";
end;
procedure TForm1.NMFTP1PacketSent(Sender: TObject);
begin
StatusBar1.SimpleText := "Sent "+IntToStr(NMFTP1.BytesSent)+" bytes of "+IntToStr(NMFTP1.BytesTotal)+" total";
end;
procedure TForm1.NMFTP1TransactionStart(Sender: TObject);
begin
Memo1.Lines.Add("Data transfer start");
end;
procedure TForm1.NMFTP1TransactionStop(Sender: TObject);
begin
Memo1.Lines.Add("Data transfer end");
end;
procedure TForm1.NMFTP1Success(Trans_Type: TCmdType);
var
I: Integer;
begin
case Trans_Type of
cmdList:
begin
for I := 0 to (StringGrid1.ColCount - 1) do
StringGrid1.Cols[I].Clear;
StringGrid1.RowCount := NMFTP1.FTPDirectoryList.name.Count;
StringGrid1.ColCount := 4;
StringGrid1.Cells[0, 0] := "Filename";
StringGrid1.Cells[1, 0] := "File Size";
StringGrid1.Cells[2, 0] := "Modified Date";
StringGrid1.Cells[3, 0] := "Attributes";
for I := 0 to (NMFTP1.FTPDirectoryList.name.Count - 1) do
with NMFTP1.FTPDirectoryList do
begin
StringGrid1.Cells[0, I+1] := name[I];
StringGrid1.Cells[1, I+1] := Size[I];
StringGrid1.Cells[2, I+1] := ModifDate[I];
StringGrid1.Cells[3, I+1] := Attribute[I];
end;
end;
cmdChangeDir:
begin
Memo1.Lines.Add("ChangeDir successful");
NMFTP1.List;
end;
cmdMakeDir: Memo1.Lines.Add("MakeDir successful");
cmdRemoveDir: Memo1.Lines.Add("RemoveDir successful");
cmdDelete: Memo1.Lines.Add("Delete successful");
cmdRename: Memo1.Lines.Add("Rename successful");
cmdReInit: Memo1.Lines.Add("Reinitialize successful");
cmdCurrentDir: Memo1.Lines.Add("CurrentDir successful");
end;
end;
procedure TForm1.NMFTP1UnSupportedFunction(Trans_Type: TCmdType);
begin
case Trans_Type of
cmdChangeDir: Memo1.Lines.Add("ChangeDir not supported by this server");
cmdMakeDir: Memo1.Lines.Add("MakeDir not supported by this server");
cmdDelete: Memo1.Lines.Add("Delete not supported by this server");
cmdRemoveDir: Memo1.Lines.Add("RemoveDir not supported by this server");
cmdList: Memo1.Lines.Add("List not supported by this server");
cmdRename: Memo1.Lines.Add("Rename not supported by this server");
cmdUpRestore: Memo1.Lines.Add("UploadRestore not supported by this server");
cmdDownRestore: Memo1.Lines.Add("DownloadRestore not supported by this server");
cmdDownload: Memo1.Lines.Add("Download not supported by this server");
cmdUpload: Memo1.Lines.Add("Upload not supported by this server");
cmdAppend: Memo1.Lines.Add("UploadAppend not supported by this server");
cmdReInit: Memo1.Lines.Add("Reinitialize not supported by this server");
cmdAllocate: Memo1.Lines.Add("Allocate not supported by this server");
cmdNList: Memo1.Lines.Add("NList not supported by this server");
cmdDoCommand: Memo1.Lines.Add("DoCommand not supported by this server");
cmdCurrentDir: Memo1.Lines.Add("CurrentDir not supported by this server");
end;
end;
procedure TForm1.Button11Click(Sender: TObject);
Var RemoteFileName: String;
begin
if InputQuery("Download", "Remote File: ", RemoteFileName) then
if OpenDialog1.Execute then
NMFTP1.Download(RemoteFileName, OpenDialog1.FileName);
end;
procedure TForm1.Button12Click(Sender: TObject);
var
LocalFile,
RemoteFile: String;
F: File of Byte;
FSize: Integer;
O: TOpenDialog;
begin
O := TOpenDialog.Create(Self);
try
O.Title := "Select file to upload";
if O.Execute then
if InputQuery("Choose Remote File Name", "Filename?", RemoteFile) then
begin
LocalFile := O.FileName;
AssignFile(F, LocalFile);
Reset(F);
FSize := FileSize(F);
CloseFile(F);
NMFTP1.Allocate(FSize);
NMFTP1.Upload(LocalFile, RemoteFile);
end;
finally
O.Free;
end;
end;
end.
← →
ALEKCEY (2004-02-14 17:36) [3]всё здорово и прекрасно, но список фаилов на сервере всёравно нигде не показывается
Страницы: 1 вся ветка
Форум: "Сети";
Текущий архив: 2004.04.18;
Скачать: [xml.tar.bz2];
Память: 0.49 MB
Время: 0.039 c