Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2340932
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:08:46

程序见下#include
#pragma hdrstop

#include "FTP_Ex.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFTPMain *FTPMain;
//---------------------------------------------------------------------------
__fastcall TFTPMain::TFTPMain(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TFTPMain::btConnectClick(TObject *Sender)
{
        if(ftp1->Connected)ftp1->Disconnect();//如果已连接则中断之
        ftp1->Host=edHost->Text;//输入的主机名
        ftp1->UserID=edUser->Text;//输入的用户名
        ftp1->Password=edPassword->Text;//密码
        if(ckUseProxy->Checked)//如果要用代理
        {
                ftp1->Proxy=edProxy->Text;//代理名
                ftp1->ProxyPort=edProxyPort->Text.ToInt();//端口
        }
        ftp1->Connect();//连接
        ltMess->Items->Add(ftp1->TransactionReply);//显示信息
        ltFile->Items->Clear();
        ftp1->List();//取得文件列表
        ltFile->Items->AddStrings(ftp1->FTPDirectoryList->name);//在列表框中显示

}
//---------------------------------------------------------------------------
//中断连接
void __fastcall TFTPMain::btDisconnectClick(TObject *Sender)
{
        if(ftp1->Connected)ftp1->Disconnect();
        ltMess->Items->Add(ftp1->TransactionReply);
        ltFile->Items->Clear();
}
//---------------------------------------------------------------------------
//匿名登录
void __fastcall TFTPMain::ckNonameClick(TObject *Sender)
{
        if(ckNoname->Checked)
        {
                edUser->Text="anonymous";
                edPassword->Text="XXXX@XXX.XXX";
        }
        edUser->Enabled=!(edUser->Enabled);
        edPassword->Enabled=!(edPassword->Enabled);
        lbUser->Enabled=!(lbUser->Enabled);
        lbPassword->Enabled=!(lbPassword->Enabled);
}
//---------------------------------------------------------------------------
//执行命令
void __fastcall TFTPMain::btSendCommandClick(TObject *Sender)
{
        ftp1->DoCommand(cbCommand->Text);
        ltMess->Items->Add(ftp1->TransactionReply);
}
//---------------------------------------------------------------------------
//使用代理服务器
void __fastcall TFTPMain::ckUseProxyClick(TObject *Sender)
{
        edProxy->Enabled=!(edProxy->Enabled);
        edProxyPort->Enabled=!(edProxyPort->Enabled);
        lbProxy->Enabled=!(lbProxy->Enabled);
        lbProxyPort->Enabled=!(lbProxyPort->Enabled);
}
//---------------------------------------------------------------------------
//重新取得文件列表
void __fastcall TFTPMain::btListClick(TObject *Sender)
{
        ltFile->Items->Clear();
        ftp1->List();
        ltFile->Items->AddStrings(ftp1->FTPDirectoryList->name);
}
//---------------------------------------------------------------------------
//下载文件
void __fastcall TFTPMain::Button1Click(TObject *Sender)
{
        int i=ltFile->ItemIndex;
        if(i==-1)return;
        if(ftp1->FTPDirectoryList->Size->Strings[i]!="0")//如果是文件下载
        {
                AnsiString tdir=ExtractFilePath(Application->ExeName);
                if(InputQuery("请输入保存的目录","请输入保存的目录",tdir))
                {
                        ftp1->Mode(MODE_IMAGE);
                        ftp1->Download(ftp1->FTPDirectoryList->name->Strings[i],"");
                }
        }
        else//如果是目录打开
        {
                ftp1->ChangeDir(ftp1->FTPDirectoryList->name->Strings[i]);
                ltFile->Items->Clear();
                ftp1->List();
                ltFile->Items->AddStrings(ftp1->FTPDirectoryList->name);
        }
}
//---------------------------------------------------------------------------
//上传文件
void __fastcall TFTPMain::btUpdataClick(TObject *Sender)
{
        AnsiString fn=InputBox("上传","请输入你要上传的文件名","");
        if(FileExists(fn))
        {
                ftp1->Upload(fn,ExtractFileName(fn));
                this->btListClick(NULL);


--------------------next---------------------

阅读(1215) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~