FTP上传文件问题(50分)

  • 主题发起人 主题发起人 大狗熊
  • 开始时间 开始时间

大狗熊

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,wininet, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
Session:HINTERNET;
Server :HINTERNET;
hWnd:Thandle;
strWin :string;
implementation

{$R *.dfm}
function GetOnlineStatus : Boolean;
var ConTypes : Integer;
begin
ConTypes := INTERNET_CONNECTION_MODEM + INTERNET_CONNECTION_LAN + INTERNET_CONNECTION_PROXY;
if (InternetGetConnectedState(@ConTypes, 0) = False) then Result := False else Result := True;
end;

procedure FtpConnect() ;
begin
Session := InternetOpen('Yalong', INTERNET_OPEN_TYPE_DIRECT, '', '', 0);
Server := InternetConnect(Session, 'ftp6.25idc.cn', 21, 'user', 'pass', INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
If Server = nil Then
begin
InternetCloseHandle(Session);
form1.caption:='s';
End;
End;
//上传文件
procedure FtpUp();
var
Kam:string;
hFile:HINTERNET;
sFile:File;
cnt:DWORD;
Buf:array [0..1023] of byte;
nRet:DWORD;
begin
FtpSetCurrentDirectory (Session, '/');
Kam := '/' + datetimetostr(Now)+'.txt';
hFile := FtpOpenFile(Server, pchar(Kam), GENERIC_WRITE, FTP_TRANSFER_TYPE_BINARY, 0);
if hFile=nil then
begin
try
Assignfile(sFile,'yalong.txt');
Reset(sFile,1);
repeat
BlockRead(sFile,Buf,sizeof(Buf),Cnt);
InternetWriteFile(hFile, @(Buf[0]), Cnt, nRet);
until Cnt<sizeof(Buf);
finally
Closefile(sFile);
InternetCloseHandle(Session);
//DeleteFile(strWin + '/' + 'yalong.txt');
end
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if GetOnlineStatus = true then
begin
FtpConnect;
FtpUp;
end;
end;

end.


呵呵,搞的这个不能用,请高手指点,怎么能FTP上传文件,要最简单的那种
默认直接覆盖原来的
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,wininet, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
hFTPSession,hInternetSession:HINTERNET;
Server :HINTERNET;
hWnd:Thandle;
strWin :string;
implementation

{$R *.dfm}
function GetOnlineStatus : Boolean;
var ConTypes : Integer;
begin
ConTypes := INTERNET_CONNECTION_MODEM + INTERNET_CONNECTION_LAN + INTERNET_CONNECTION_PROXY;
if (InternetGetConnectedState(@ConTypes, 0) = False) then Result := False else Result := True;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if GetOnlineStatus = true then
begin

hFTPSession:=InternetConnect(hInternetSession, 'ftp.freett.com',21,'hacker77','123456', INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
if hFTPSession=nil then memo1.Lines.Add('ftp 连接失败.')
else memo1.Lines.Add('ftp 连接成功.');
;
//设定服务端目录
FtpSetCurrentDirectory(hFTPSession,'/****');
if FileExists('c:/test.txt') then begin
if FtpPutFile(hFTPSession,pchar('c:/test.txt'),'test.txt',INTERNET_FLAG_TRANSFER_BINARY,0) then
memo1.Lines.Add('发送完毕')
else memo1.Lines.Add('发送失败');
end else memo1.Lines.Add('要发送的文件不存在');

InternetCloseHandle(hFTPSession);
end;
end;
end.

这个也一直失败...
 
后退
顶部