2016-04-21 65 views
3

我是拉撒路新人的几个月。我一直在尝试创建一个小型FTP程序,它将在登录后发送一个小文件。我完成了所有粘性的工作,我唯一关心的是FTP部分。我得到了一大堆错误的,我一直在努力安装正确的软件包有没有简单的方法在拉撒路代码中使用FTP功能

我的FTP代码如下所示

function TModel.Send(LocalFile : string; remoteFile : string; RemoteDir : string) : boolean; 
//=========================================================================== 
//  ********************************************************************** 
//  * Send a file to the FTP server          * 
//  ********************************************************************** 
//--------------------------------------------------------------------------- 
var 
    rc : boolean; 
begin 
    // Create the FTP Client object and set the FTP parameters 
    FTPClient := TFTPSend.Create; 
    with FTPClient do begin 
     TargetPort := cFtpProtocol; 
     TargetHost := fHost; // these were properties set somewhere else 
     UserName := fUserID; 
     Password := fPassword; 
     //----------------------------------------------------------------------- 
     // bail out if the FTP connect fails 
     if not LogIn then exit; 
     //------------------------------------------------------------------------ 

     // Set filename to FTP 
     DirectFileName := LocalFile; 
     DirectFile := True; 
     //------------------------------------------------------------------------ 

     // change directory if requested 
     if RemoteDir <> '' then ChangeWorkingDir(RemoteDir); 
     //------------------------------------------------------------------------ 

     // STOR file to FTP server. 
     rc := StoreFile(RemoteFile,false); 
     //------------------------------------------------------------------------ 

     // close the connection 
     LogOut; 
     //------------------------------------------------------------------------ 
     // free the FTP client object 
     free; 
     //------------------------------------------------------------------------ 
    end; 
    Result := rc; 
//=========================================================================== 
end; 

感谢您的帮助。

回答

3

Oh Lazarus XD。我不确定是否有任何简单的方法。我试图做类似的事情而回,但我没有得到全面整理,虽然它....但我确实得到了FTP的工作看看我的代码如下

begin 
    IdSMTP := TIdSMTP.Create(nil); 
    try 
    IdSMTP.Host := 'smtp.jonas.com'; 
    IdSMTP.Port := 587; 
    IdSMTP.AuthType := satDefault; 
    IdSMTP.Username := '[email protected]'; 
    IdSMTP.Password := 'TeCat#!'; 
    IdSMTP.Connect; 
    if IdSMTP.Authenticate then; 
    begin 
     IdMessage := TIdMessage.Create(nil); 
     try 
     IdMessage.From.Name := 'Jonas Server'; 
     IdMessage.From.Address := '[email protected]'; 
     IdMessage.Subject := subject; 
     IdMessage.Body.AddStrings(message); 
     IdEmailAddressItem := IdMessage.Recipients.Add; 
     IdEmailAddressItem.Address := '[email protected]'; 

     IdSMTP.Send(IdMessage); 
     finally 
     IdMessage.Free; 
     end; 
    end; 
    IdSMTP.Disconnect; 
    finally 
    IdSMTP.Free; 
    end; 
end; 

我看你是使用Synapse我不记得我用过什么....它介于indy,lnet或突触之间。只是让我知道,如果你需要这些包我把它们保存在我的保管箱:)也检查出THIS网站这是一个整个网站致力于拉兹.....伟大(͡°͜ʖ͡°)

+2

谢谢你的码 –

相关问题