Chinaunix首页 | 论坛 | 博客
  • 博客访问: 333376
  • 博文数量: 65
  • 博客积分: 1770
  • 博客等级: 上尉
  • 技术积分: 1125
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-13 14:31
文章分类

全部博文(65)

文章存档

2016年(1)

2014年(2)

2013年(5)

2012年(18)

2011年(39)

分类: C/C++

2011-08-07 17:31:12

步骤:
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) |
给主人留下些什么吧!~~