建立基于对话框的MFC应用程序CMfcFtpWinInetDlg:

  1、首先Dlg类中包含头文件 #include "afxinet.h"

  2、添加成员变量:

 C++ Code 
1
2
3
 
  private:
    CFtpConnection*     m_pFtpConnection;
    CInternetSession    m_Session;

 

  3、在OnInitDialog中加入Ftp连接代码:

 C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
// TODO: Add extra initialization here
m_pFtpConnection = NULL;

try
{
    // Here usr is the username, pwd is the password 
    // and ftpsite.com is the name of the ftp site which
    // you want to connect to.

m_pFtpConnection = m_Session.GetFtpConnection(_T("localhost"), _T("Manager"), _T("kingview"), INTERNET_INVALID_PORT_NUMBER);
}
catch(CInternetException *pEx)
{
    pEx->ReportError(MB_ICONEXCLAMATION);
    m_pFtpConnection = NULL;
    pEx->Delete();
}

  4、在OK和Cancel按钮中加入关闭Ftp连接代码:

 C++ Code 
1
2
3
4
5
6
 
// TODO: Add your control notification handler code here
m_Session.Close();
m_pFtpConnection->Close();

if(m_pFtpConnection != NULL)
    delete m_pFtpConnection;

   5、添加Upload以及Download按钮代码:

 C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
void CMfcFtpWinInetDlg::OnBnClickedBtnUpload()
{
    // TODO: Add your control notification handler code here
    CFileFind Finder;
    CString strFileName;

// Here c:\\Myfile.bmp is the name of the file that you want 
    // to upload. It neednt necessarily be a bitmap file. You 
    // can upload any file that you want to.
    // The CString strFileName is used so that the same name 
    // is uploaded to the ftp server.
    // After uploading, the file in the ftp server will have 
    // the same name as your local file.
    // You can also rename it to anything

if(Finder.FindFile(_T("F:\\hot.gif"))==TRUE)
    {
        Finder.FindNextFile();
        strFileName = Finder.GetFileName();
        Finder.Close();
    }

BOOL bUploaded = m_pFtpConnection->PutFile( _T("F:\\hot.gif"),
                                                strFileName,
                                                FTP_TRANSFER_TYPE_BINARY,
                                                );

AfxMessageBox(_T("Uploaded Successfully"));
}

void CMfcFtpWinInetDlg::OnBnClickedBtnDownload()
{
    // TODO: Add your control notification handler code here
    BOOL bDownloaded = m_pFtpConnection->GetFile(   _T("hot.gif"),
                                _T("D:\\hot.gif"),
                                TRUE,
                                FILE_ATTRIBUTE_NORMAL,
                                FTP_TRANSFER_TYPE_BINARY,
                                );
    AfxMessageBox(_T("Downloaded Successfully"));
}

   API参数说明,请参考MSDN。

使用MFC WinInet进行FTP中文件的简单上传和下载功能的更多相关文章

  1. 基于commons-net实现ftp创建文件夹、上传、下载功能

    原文:http://www.open-open.com/code/view/1420774470187 package com.demo.ftp; import java.io.FileInputSt ...

  2. Java实现FTP文件与文件夹的上传和下载

    Java实现FTP文件与文件夹的上传和下载 FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为"文传协议".用于Internet上的控制 ...

  3. c# ftp创建文件(非上传文件)

    c#  ftp创建文件(非上传文件) 一.奇葩的故事: 今天项目中遇到这么个奇葩的问题,ftp文件传输完成后要在ftp目录下另一个文件夹下创建对应的空文件,听说是为了文件的完整性,既然这么说,那么就必 ...

  4. iOS开发中文件的上传和下载功能的基本实现-备用

    感谢大神分享 这篇文章主要介绍了iOS开发中文件的上传和下载功能的基本实现,并且下载方面讲到了大文件的多线程断点下载,需要的朋友可以参考下 文件的上传 说明:文件上传使用的时POST请求,通常把要上传 ...

  5. JavaWeb中的文件上传和下载功能的实现

    导入相关支持jar包:commons-fileupload.jar,commons-io.jar 对于文件上传,浏览器在上传的过程中是将文件以流的形式提交到服务器端的,如果直接使用Servlet获取上 ...

  6. win7下利用ftp实现华为路由器的上传和下载

    win7下利用ftp实现华为路由器的上传和下载 1.  Win7下ftp的安装和配置 (1)开始->控制面板->程序->程序和功能->打开或关闭Windows功能 (2)在Wi ...

  7. 【Python学习 】Python实现的FTP上传和下载功能

    一.背景 最近公司的一些自动化操作需要使用Python来实现FTP的上传和下载功能.因此参考网上的例子,撸了一段代码来实现了该功能,下面做个记录. 二.ftplib介绍 Python中默认安装的ftp ...

  8. secureCRT简单上传、下载文件记录

    secureCRT简单上传.下载文件记录: 1)sz下载 -y 覆盖 2)rz上传 -y 覆盖 3)以上两个命令属于安装时包含在“Dial-up Networking Support"组中 ...

  9. 与众不同 windows phone (13) - Background Task(后台任务)之后台文件传输(上传和下载)

    原文:与众不同 windows phone (13) - Background Task(后台任务)之后台文件传输(上传和下载) [索引页][源码下载] 与众不同 windows phone (13) ...

随机推荐

  1. Java experts blog

    https://blogs.oracle.com/poonam/ https://blogs.oracle.com/poonam/entry/updates_to_the_java_troublesh ...

  2. 每日英语:Hong Kong Lifestyle Strains City's Resources

    Hong Kong's rapacious consumption and waste production is straining its natural resources and could ...

  3. Install haroopad on centos7

    1.Install libs sudo yum install systemd-libs -y 2.Download haroopad goto haroopad1 download bin pack ...

  4. flask celery 使用方法

    一.安装 由于celery4.0不支持window,如果在window上安装celery4.0将会出现下面的错误flask_clery 你现在只能安装pip install celery==3.1 二 ...

  5. The power of now

    惊喜的发现,在这个短暂而又漫长的盛夏里心情开始随天气而变了(*^__^*) ...... <秘密>和<当下的力量>两者都一样,看起来费劲,不过还真的有点道理. <冰与火之 ...

  6. 从JDBC程序看为什么需要Mybatis

    package com.xuebusi.jdbc; import java.sql.*; /** * 从JDBC程序看为什么需要Mybatis * * 1.加载驱动程序和数据库连接所需要的url.用户 ...

  7. Logstash5.3借助临时字段修改@timestamp为北京时间,方便按天生成output文件

    $more config/first-pipeline.conf input { beats { port => " } } filter { if [type] == "s ...

  8. ID、Class和标签选择器优先级

    按一般论:ID > Class > 标签 1.如以下样式: <div id="id" class="class">选择器优先权</ ...

  9. 在input中回车后页面提交导致出现HTTP 错误 405.0 - Method Not Allowed

    前些时间在做一个搜索功能时发现一个比較有意思的现象,场景是这种:在一个模态窗体中是一个订单列表.页面的顶部有若干个状态筛选框和一个搜索keyword输入框,当焦点在keyword输入框时按回车,本来是 ...

  10. C# 异常类型

    Exception 类  描述 SystemException 其他用户可处理的异常的基本类 ArgumentException 方法的参数是非法的 ArgumentNullException 一个空 ...