想写一个简单的FTP上传下载的东西,大家给给意见,用控件不用控件分别怎么写,不用控件用FTP协议写会很复杂吗?

CPerlAsm_Lx 2003-10-27 04:28:03
想写一个简单的FTP上传下载的东西,大家给给意见,用控件不用控件分别怎么写,不用控件用FTP协议写会很复杂吗?
...全文
52 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
CPerlAsm_Lx 2003-11-07
  • 打赏
  • 举报
回复
netsys2(来电) 顺便工程也给我看看??
netsys2 2003-11-06
  • 打赏
  • 举报
回复
什么上传文件?

提示一下?
CPerlAsm_Lx 2003-11-06
  • 打赏
  • 举报
回复
天府,你的工程可以看看嘛?这样看了好久。还是糊涂。

Ywg78 2003-11-05
  • 打赏
  • 举报
回复
来电!你上传文件做好了没有,小女子等着你的答案
netsys2 2003-11-05
  • 打赏
  • 举报
回复
是FTP客户端吗?

BCB有控件和例子,不难。



cb\examples\fastnet\ftp
libertysigil 2003-11-05
  • 打赏
  • 举报
回复
楼上的,怎么没有注释啊~~~~

可以加上注释吗?
qiong12 2003-11-03
  • 打赏
  • 举报
回复
下面是实现文件:
//---------------------------------------------------------------------------


#pragma hdrstop

#include "utFtp.h"
#include <memory>
using namespace std;

//---------------------------------------------------------------------------

#pragma package(smart_init)

TMyFtp *m_MyFtp;

TMyFtp::TMyFtp()
{
m_ftp = new TIdFTP(NULL);
m_vecErrorMsg.Empty();
m_nErrorNo = 0;
};

TMyFtp::TMyFtp(TIdFTP *idFtp)
{
m_ftp = idFtp;
m_vecErrorMsg.Empty();
m_nErrorNo = 0;
};

TMyFtp::~TMyFtp()
{
CloseFtp();
};

void __fastcall TMyFtp::InitFtp(
const AnsiString &strTargetIp,
int nFtpPort,
const AnsiString &strFtpUser,
const AnsiString &strFtpPassword
)
{
m_ftp->Host = strTargetIp;
m_ftp->Port = nFtpPort;
m_ftp->User = strFtpUser;
m_ftp->Password = strFtpPassword;
m_ftp->TransferType = ftASCII;
};

bool __fastcall TMyFtp::OpenFtp(bool bErrorMarked, bool bClearErrorMsg)
{
if (bClearErrorMsg)
m_vecErrorMsg->empty();
try
{
if (!m_ftp->Connected())
{
m_ftp->Connect();
m_strFtpLoginPath = m_ftp->RetrieveCurrentDir();
}
}
catch(Exception &e)
{
m_vecErrorMsg.push_back(m_ftp->Host + " " + m_ftp->User + " " + m_ftp->Password " connect error: " + e.Message);
if (bErrorMarked)
m_nErrorNo = CONNECT_ERROR;
return false;
}
m_nErrorNo = 0;
return true;
};

bool __fastcall TMyFtp::CloseFtp(bool bErrorMarked, bool bClearErrorMsg)
{
if (bClearErrorMsg)
m_vecErrorMsg.empty();
try
{
if (m_ftp->Connected())
{
m_ftp->Abort();
m_ftp->Disconnect();
}
}
catch(Exception &e)
{
m_vecErrorMsg.push_back(m_ftp->Host + " Disconnect error: " + e.Message);
if (bErrorMarked)
m_ErrorNo = DISCONNECT_ERROR;
return false;
}
m_nErrorNo = 0;
return true;
};

bool __fastcall TMyFtp::ListFtpFile(
const AnsiString &strDir,
TStrings *ssTemp,
bool bAutoOpenAndClose
)
{
try
{
if ( bAutoOpenAndClose && (!OpenFtp()) )
return false;
if (m_ftp->Connected())
{
m_ftp->ChangeDir(m_strFtpLoginPath);
m_ftp->ChangeDir(strDir);
m_ftp->List(ssTemp, "*", false);
}
if (bAutoOpenAndClose && (!CloseFtp()))
{
if
return false;
}
}
catch(Exception &e)
{
m_strErrMsg = AnsiString("list ") + strDir + " wrong: " + e.Message;
if (bAutoOpenAndClose)
{
if (!CloseFtp())
return false;
}
return false;
}

return true;
};

bool __fastcall TMyFtp::GetFtpFile(
const AnsiString &strDir,
const AnsiString &strSourceFile,
const AnsiString &strDestFile,
bool bAutoOpenAndClose)
{
try
{
auto_ptr<TStrings> ssFileList(new TStringList());
AnsiString strCurrPath;
if ( bAutoOpenAndClose && (!OpenFtp()) )
return false;
if (m_ftp->Connected())
{
m_ftp->ChangeDir(m_strFtpLoginPath);
m_ftp->ChangeDir(strDir);
m_ftp->List(ssFileList.get(), strSourceFile, false);
if (ssFileList->IndexOf(strSourceFile) > -1)
{
m_ftp->Get(strSourceFile, strDestFile, false);
}
else
{
m_strErrMsg = (AnsiString)"get " + strSourceFile + " wrong: such file";
if ( bAutoOpenAndClose && (!CloseFtp()) )
{

}
return false;
}
}
if (bAutoOpenAndClose)
{
CloseFtp();
}
}
catch(Exception &e)
{
m_strErrMsg = (AnsiString)"get " + strSourceFile + " wrong: " + e.Message;
if (bAutoOpenAndClose)
{
CloseFtp();
}
return false;
}

return true;
};

bool __fastcall TMyFtp::PutFtpFile(
const AnsiString &strDir,
const AnsiString &strSourceFile,
const AnsiString &strDestFile,
bool bAutoOpenAndClose = true
)
{
try
{
auto_ptr<TStrings> ssFileList(new TStringList());
AnsiString strCurrPath;
if (bAutoOpenAndClose)
{
OpenFtp();
}
if (m_ftp->Connected())
{
m_ftp->ChangeDir(m_strFtpLoginPath);
m_ftp->ChangeDir(strDir);
m_ftp->List(ssFileList.get(), strSourceFile, false);
if (ssFileList->IndexOf(strSourceFile) > -1)
{
m_ftp->Put(strSourceFile, strDestFile, false);
}
else
{
m_strErrMsg = (AnsiString)"get " + strSourceFile + " wrong: such file";
if (bAutoOpenAndClose)
{
CloseFtp();
}
return false;
}
}
if (bAutoOpenAndClose)
{
CloseFtp();
}
}
catch(Exception &e)
{
m_strErrMsg = (AnsiString)"get " + strSourceFile + " wrong: " + e.Message;
if (bAutoOpenAndClose)
{
CloseFtp();
}
return false;
}

return true;
}

AnsiString __fastcall TMyFtp::GetLastErrorMsg()
{
return m_strErrMsg;
}
请大家都提意见
qiong12 2003-11-03
  • 打赏
  • 举报
回复
我最近刚写了一个,就拿出来大家看看,下面是头文件:
//---------------------------------------------------------------------------

#ifndef utFtpH
#define utFtpH
//---------------------------------------------------------------------------
#include <IdBaseComponent.hpp>
#include <IdComponent.hpp>
#include <IdFTP.hpp>
#include <IdTCPClient.hpp>
#include <IdTCPConnection.hpp>
#include <vector>
using namespace std;

/*******************************************************************************
* 类 名: TMyFtp
* 描 述: FTP控制类
* 作 者: ChenTianFu
********************************************************************************/
const int CONNECT_ERROR = 1;
const int DISCONNECT_ERROR = 2;
const int LIST_ERROR = 3;
const int GET_ERROR = 4;
const int PUT_ERROR = 5;

class TMyFtp
{
private:
TIdFTP *m_ftp;
int m_nErrorNo;
vector<AnsiSting> m_vecErrorMsg;
AnsiString m_strFtpLoginPath;
TMyFtp(const TMyFtp &yourFtp)
{
};
TMyFtp& operator=(const TMyFtp &yourFtp)
{
};
public:
TMyFtp();
TMyFtp(TIdFTP *idFtp);
~TMyFtp();

void __fastcall InitFtp(
const AnsiString &strTargetIp,
int nFtpPort,
const AnsiString &strFtpUser,
const AnsiString &strFtpPassword
);
bool __fastcall OpenFtp(bool bErrorMarked = true, bool bClearErrorMsg=true);
bool __fastcall CloseFtp(bool bErrorMarked = true, bool bClearErrorMsg=true);

bool __fastcall ListFtpFile(
const AnsiString &strDir,
TStrings *ssTemp,
bool bAutoOpenAndClose = true
);
bool __fastcall GetFtpFile(
const AnsiString &strDir,
const AnsiString &strSourceFile,
const AnsiString &strDestFile,
bool bAutoOpenAndClose = true);
bool __fastcall PutFtpFile(
const AnsiString &strDir,
const AnsiString &strSourceFile,
const AnsiString &strDestFile,
bool bAutoOpenAndClose = true
);

AnsiString __fastcall GetLastErrorMsg();
};


extern TMyFtp *m_MyFtp;
#endif
CPerlAsm_Lx 2003-11-02
  • 打赏
  • 举报
回复
Aweay 我没找到可以帮忙吗??
Siney 2003-11-02
  • 打赏
  • 举报
回复
如果想简单的话就一个函数就可以了,在WinINet Functions函数族里,有一个专门从http,ft上下载文件的函数,非常好用,很多下载软件都是直接使用这个函数的。

在http://www.vckbase.com里这个函数的详细用发和例子。


CPerlAsm_Lx 2003-11-02
  • 打赏
  • 举报
回复
UP
xiaolong83 2003-11-02
  • 打赏
  • 举报
回复
控件非常方便
CPerlAsm_Lx 2003-10-27
  • 打赏
  • 举报
回复
说是说,那位给点提示,或者发代码给我看看吗。三十年孤独。给你发了消息。既然容易可以给我看看你怎么写的吗?
ljianq 2003-10-27
  • 打赏
  • 举报
回复
用控件容易,不用控件也简单。
我不懂电脑 2003-10-27
  • 打赏
  • 举报
回复
用控件可以用TIdFtpClient;
不用控件也很容易,我最近因为项目需要不用控件编了一个
weixing979 2003-10-27
  • 打赏
  • 举报
回复
用控件多方便啊。根据属性和事件写。找本书看看吧

1,316

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧