2016-04-21 52 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

謝謝你的碼 –

相關問題