首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Lazarus代码中是否有使用FTP功能的简单方法?

问在Lazarus代码中是否有使用FTP功能的简单方法?
EN

Stack Overflow用户
提问于 2016-04-21 08:28:04
回答 1查看 554关注 0票数 3

我刚到拉撒路才几个月。我一直在尝试创建一个小FTP程序,它将在登录后发送一个小文件。我已经做了所有愚蠢的事情,我唯一关心的是FTP部分。我得到了很多错误,我一直在努力安装正确的软件包。

我的FTP代码如下所示

代码语言:javascript
复制
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;

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-21 12:15:03

哦拉撒路XD。不过,我不确定是否有什么简单的办法。一段时间前我试着做一些类似的事情,但是我没有抽出时间去完成它.但是我确实让FTP工作了--看看下面的代码

代码语言:javascript
复制
 begin
  IdSMTP := TIdSMTP.Create(nil);
  try
    IdSMTP.Host := 'smtp.jonas.com';
    IdSMTP.Port := 587;
    IdSMTP.AuthType := satDefault;
    IdSMTP.Username := 'server@jonas.com';
    IdSMTP.Password := 'TeCat#!';
    IdSMTP.Connect;
    if IdSMTP.Authenticate then;
    begin
      IdMessage := TIdMessage.Create(nil);
      try
        IdMessage.From.Name := 'Jonas Server';
        IdMessage.From.Address := 'server@jonas.com';
        IdMessage.Subject := subject;
        IdMessage.Body.AddStrings(message);
        IdEmailAddressItem := IdMessage.Recipients.Add;
        IdEmailAddressItem.Address := 'server@jonas.com';

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

我看你在用Synapse我不记得我用了什么..。在indy,lnet或synapse之间。只要告诉我,如果你需要这些包,我把它们保存在我的dropbox上:)也可以查看这网站,它是一个专门为Laz.....GREAT (͡°͜ʖ͡°)服务的网站。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36763930

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档