求用NMFTP编写下载程序的源代码

huaqglxy2004 2005-03-28 03:49:46
求用NMFTP编写下载程序的源代码
...全文
285 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
dargons 2005-04-22
  • 打赏
  • 举报
回复
在C++ Builder的帮助中有具体的帮助文档,可以试一下:
建立连接:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
NMFTP1->ReportLevel=Status_Basic;
NMFTP1->Host=Edit1->Text;//目标地址
NMFTP1->Port=StrToInt(Edit2->Text);//通常为21
NMFTP1->UserID=Edit3->Text;//用户名,通常为anonymous
NMFTP1->Password=Edit4->Text;//口令,通常为yourname@yourcompany.com
NMFTP1->Connect();
if(StatusBar1->SimpleText=="Connected!")
Memo1->Text="正在连接"+Edit1->Text+"......\n"+"恭喜你,连接成功!!";
}
显示列表:
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Memo1->Text="";
NMFTP1->List();
}
下载文件:
void __fastcall TForm1::Button4Click(TObject *Sender)
{
OpenDialog1->Title="Select File path to Load File!";
if(OpenDialog1->Execute())
NMFTP1->Download(Edit5->Text,OpenDialog1->FileName);
}
mmking33 2005-04-06
  • 打赏
  • 举报
回复
经过一段时间的努力,终于实现了利用indyftp进行断点下载上传。主要思想是1个连接管控制,还有连接管数据传输。http://community.csdn.net/Expert/topic/3870/3870928.xml?temp=.4899713
dargons 2005-04-06
  • 打赏
  • 举报
回复
在IPWorks控件中有这方面的例子.
感兴趣的话可以看一下.
那上面给出的比较详细!!
huaqglxy2004 2005-04-05
  • 打赏
  • 举报
回复
我没有收到呀!
constantine 2005-04-01
  • 打赏
  • 举报
回复
ok了,去收吧
constantine 2005-04-01
  • 打赏
  • 举报
回复
马上给你们发==
copico 2005-04-01
  • 打赏
  • 举报
回复
yudengkui-010@163.com
oyclkelly 2005-04-01
  • 打赏
  • 举报
回复
可以给我发一份吗oyclkelly@163.com
谢谢
constantine 2005-03-30
  • 打赏
  • 举报
回复
要代码留个email
constantine 2005-03-30
  • 打赏
  • 举报
回复
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner){}
void __fastcall TForm1::BitBtn5Click(TObject *Sender)
{
if(NMFTP1->Connected)
{
NMFTP1->Disconnect();
ListBox1->Clear();
}
else
{
if(this->CheckBox1->Checked)
{
this->NMFTP1->Proxy = this->PServer->Text;
this->NMFTP1->ProxyPort = StrToInt(PPort->Text);
}
Form1->NMFTP1->Host = HostTxt->Text;
Form1->NMFTP1->Port = StrToInt(PortTxt->Text);
// Form1->NMFTP1->TimeOut = 1000;
Form1->NMFTP1->UserID = UserTxt->Text;
Form1->NMFTP1->Password = PassTxt->Text;
Form1->NMFTP1->Connect();
}
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ListBox1->Clear();
NMFTP1->List();
}
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
int i ;
String sPath;
String sTemp;
for (i = 0; i <= ListBox1->Items->Count - 1; i++)
{
sPath = ListBox1->Items->Strings[i] ;
sTemp = sPath;
sTemp.Delete(1, sTemp.Length() - 1);
// 判断所选择的是否为目录 (..) 或 (/)?
if ((sPath == "..") || (sTemp == "/"))
{
ListBox1->Selected[i] = false ;
}
if (ListBox1->Selected[i])
{
// 执行下载(Download)功能Download(<remote file>, <local file>) ;
NMFTP1->Download(sPath, LocalPath + sPath);
// 刷新本机 (local) 端目录内容
FileListBox1->Update() ;
ListBox1->Selected[i] = false ;
}
}
StatusBar1->SimpleText = "Status: File Download Complete." ;
}
void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
int i ;
AnsiString sFileName;
this->UploadDir->Text = RemotePath;
this->UploadDir->Update();
if(RemotePath != "")
{
for (i = 0; i <= FileListBox1->Items->Count - 1; i++)
{
if (FileListBox1->Selected[i])
{
sFileName = FileListBox1->FileName;
sFileName.Delete(1, LocalPath.Length());
break ;
}
}
// 执行上传(Upload)功能 Upload(<local file>, <remote file> )
NMFTP1->Upload(FileListBox1->FileName, sFileName);
ListBox1->Clear() ;
// 执行 FTP Remote 端目录浏览(LIST)功能
NMFTP1->List() ;
StatusBar1->SimpleText = "Status: File Upload Complete." ;
// 刷新本机 (local) 端目录内容
FileListBox1->Update();
}
}
void __fastcall TForm1::NMFTP1Connect(TObject *Sender)
{
StatusBar1->SimpleText = "FTP Site Connected.";
this->BitBtn5->Caption = "断开连接";
}
void __fastcall TForm1::NMFTP1ListItem(AnsiString Listing)
{
AnsiString sList,sTemp;
sList = Trim((const AnsiString)StrRScan(Listing.c_str(),' '));
sTemp = "<DIR>";
if(StrPos(Listing.c_str(),sTemp.c_str()))
{
ListBox1->Items->Add(sList + "/");
}
else
{
ListBox1->Items->Add(sList);
}
}
void __fastcall TForm1::NMFTP1PacketRecvd(TObject *Sender)
{
StatusBar1->SimpleText= "目前已下载"+IntToStr(NMFTP1->BytesRecvd)+
"字节(总共"+IntToStr(NMFTP1->BytesTotal)+"字节)";
}
void __fastcall TForm1::NMFTP1PacketSent(TObject *Sender)
{
StatusBar1->SimpleText= "目前已下载"+IntToStr(NMFTP1->BytesSent)+
"字节(总共"+IntToStr(NMFTP1->BytesTotal)+"字节)";
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
this->ListBox1->Clear();
}
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
this->NMFTP1->Abort();
}
void __fastcall TForm1::BitBtn4Click(TObject *Sender)
{
this->NMFTP1->Abort();
ListBox1->Clear();
}
void __fastcall TForm1::NMFTP1ConnectionFailed(TObject *Sender)
{
this->StatusBar1->SimpleText = "Connection failed!";
}
void __fastcall TForm1::DriveComboBox1Change(TObject *Sender)
{
LocalPath = AnsiString(DriveComboBox1->Drive) + ":\\";
DownloadDir->Text = LocalPath;
this->DownloadDir->Update();
}
void __fastcall TForm1::DirectoryListBox1Change(TObject *Sender)
{
if((StrRScan(DirectoryListBox1->Directory.c_str(),'\\') + 1) != StrEnd(DirectoryListBox1->Directory.c_str()))
{
LocalPath = AnsiString(DirectoryListBox1->Directory) + "\\";
}
else
{
LocalPath = AnsiString(DirectoryListBox1->Directory);
}
DownloadDir->Text = LocalPath;
this->DownloadDir->Update();
}
void __fastcall TForm1::FileListBox1Change(TObject *Sender)
{
this->FileListBox1->Refresh();
DownloadDir->Text = this->FileListBox1->FileName;
this->DownloadDir->Update();
}
void __fastcall TForm1::ListBox1DblClick(TObject *Sender)
{
int i ;
AnsiString sPath, sTemp ;
sPath = "";
for (i = 0; i <= ListBox1->Items->Count - 1; i++)
{

if (ListBox1->Selected[i])
{
sTemp = ListBox1->Items->Strings[i];
int judge = sTemp.Pos(".");
if(judge == 0)
{
RemotePath += ListBox1->Items->Strings[i];
sPath = ListBox1->Items->Strings[i];
}
else
{
RemotePath = "";
sPath = "";
}
break;
}
}
if (sPath != "")
{
NMFTP1->ChangeDir(Trim(sPath)); //(sPath));
this->ListBox1->Clear();
RemotePath += AnsiString("\\");
this->UploadDir->Text = RemotePath;
this->UploadDir->Update();
// 执行 FTP Remote 端目录浏览(LIST)功能
NMFTP1->List();
}
}
void __fastcall TForm1::NMFTP1Disconnect(TObject *Sender)
{
this->StatusBar1->SimpleText = "FTP Service Closed.";
this->BitBtn5->Caption = "连接服务器";
this->BitBtn5->Update();
}
void __fastcall TForm1::NMFTP1Error(TComponent *Sender, WORD Errno,
AnsiString Errmsg)
{
this->StatusBar1->SimpleText = "Error" + IntToStr(Errno) + ":" + Errmsg;
}
void __fastcall TForm1::NMFTP1HostResolved(TComponent *Sender)
{
StatusBar1->SimpleText = "Host resolved.";
}
void __fastcall TForm1::NMFTP1InvalidHost(bool &Handled)
{
MessageDlg("Invalid Host", mtError, TMsgDlgButtons() << mbOK, 0);
}
void __fastcall TForm1::NMFTP1Status(TComponent *Sender, AnsiString Status)
{
StatusBar1->SimpleText = Status;
}
void __fastcall TForm1::NMFTP1Failure(bool &Handled, TCmdType Trans_Type)
{
String sMessage ;
switch (Trans_Type)
{
case cmdChangeDir:
sMessage = "Change Directory Failed.";
break;
case cmdList:
sMessage = "List File/Directory Failed.";
break;
case cmdDownload:
sMessage = "Download File Failed.";
break;
case cmdUpload:
sMessage = "Upload File Failed.";
break;
default:
break;
}
StatusBar1->SimpleText = sMessage ;
}
void __fastcall TForm1::NMFTP1Success(TCmdType Trans_Type)
{
String sMessage ;
switch (Trans_Type)
{
case cmdChangeDir:
sMessage = "Change Directory Success.";
break;
case cmdList:
sMessage = "List File/Directory Success.";
break;
case cmdDownload:
sMessage = "Download File Success.";
break;
case cmdUpload:
sMessage = "Upload File Success.";
break;
default:
break;
}
StatusBar1->SimpleText = sMessage ;
}
NetSpider9804040 2005-03-30
  • 打赏
  • 举报
回复
报什么错!你的FTP服务器是否设置对啦?
huaqglxy2004 2005-03-30
  • 打赏
  • 举报
回复
devil2008@126.com!
谢谢constantine(飘遥的安吉儿)
samchoy 2005-03-29
  • 打赏
  • 举报
回复
就是这么多了
huaqglxy2004 2005-03-29
  • 打赏
  • 举报
回复
我也是这样做的呀,就是不行呀。你能不能把所有的原代码给我看看呀!
hbqaz_wsx 2005-03-29
  • 打赏
  • 举报
回复
怎么不行?有何提示?
samchoy 2005-03-28
  • 打赏
  • 举报
回复
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString FileName = "bcb6界面实例开发.pdf"; // 要下载的文件名
AnsiString RemoteDir = "资料"; // FTP上的目录名
AnsiString LocalDir = "d:\\"; // 下载到的本地目录名

NMFTP1->Host = "constantine.vicp.net"; // FTP地址
NMFTP1->Password = "123456"; // 密码
NMFTP1->Port = 21; // 端口号
NMFTP1->UserID = "csdnbcb"; // 用户名
NMFTP1->Connect(); // 连接FTP
if(NMFTP1->Connected)
{
NMFTP1->ChangeDir(RemoteDir); // 改变在FTP上的目录
NMFTP1->Download(FileName, LocalDir+FileName); // 下载
ShowMessage("下载完成!");
}
else
ShowMessage("连接错误!");

NMFTP1->Disconnect(); // 断开连接
}

1,317

社区成员

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

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