步骤:
1.下载Serv-U软件,然后配置好服务端
2.点击BCB中 FastNet控件组中NMFTP
将服务端的文件下载到本地,代码如下,我是以下载并显示图片为例
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString FileName = "lufei.jpg";
AnsiString RemoteDir = "/tmp/"; // 服务端存放图片的位置
AnsiString LocalDir = "e:\\tmp\\"; // 本地存放图片的位置
NMFTP1->Host = "192.168.XXX.XXX";
NMFTP1->UserID = "lemon_suifeng";
NMFTP1->Password = "pwd";
NMFTP1->Port = 21;
NMFTP1->TimeOut = 800000; // 延迟时间,可设置长点
NMFTP1->Connect();
bool IsConnected = NMFTP1->Connected;
if (IsConnected){
NMFTP1->Mode(MODE_IMAGE);
NMFTP1->Download(RemoteDir + FileName,LocalDir + FileName);
ShowMessage("download success");
}
else
ShowMessage("connect fail");
Image1->Picture->LoadFromFile(LocalDir + FileName);
NMFTP1->Disconnect();
}
将本地文件上传到服务端,代码如下:
void __fastcall TForm1::Button2Click(TObject *Sender)
{
NMFTP1->Host = "192.168.XXX.XXX";
NMFTP1->UserID = "lemon_suifeng";
NMFTP1->Password = "pwd";
NMFTP1->Port = 21;
NMFTP1->TimeOut = 800000;
AnsiString RemoteDir = "tmp/";
NMFTP1->Connect();
bool IsConnected = NMFTP1->Connected;
if (IsConnected){
NMFTP1->Mode(MODE_IMAGE);
if(OpenDialog1->Execute() == true)
NMFTP1->Upload(OpenDialog1->FileName,RemoteDir + ExtractFileName(OpenDialog1->FileName));
MessageBox(NULL,NULL,"上传成功!",0);
}
else
MessageBox(NULL,NULL,"链接错误!",0);
NMFTP1->Disconnect();
}
阅读(4870) | 评论(0) | 转发(0) |