建立基于对话框的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. maven(6)------maven坐标分析

    在不使用maven管理项目,直接使用IDE开发项目时,一个web项目中会涉及到很多技术, 比如struts2,hibernate,spring,mybatis等等,这个时候,我们就需要去各大官网下载不 ...

  2. Spring Boot干货系列:(八)数据存储篇-SQL关系型数据库之JdbcTemplate的使用

    Spring Boot干货系列:(八)数据存储篇-SQL关系型数据库之JdbcTemplate的使用 原创 2017-04-13 嘟嘟MD 嘟爷java超神学堂 前言 前面几章介绍了一些基础,但都是静 ...

  3. ubuntu 12.04下gedit查看txt中文乱码解决办法

    http://blog.sina.com.cn/s/blog_6273990801013dwv.html 由于我不能要求别人保存txt文件时必须用utf-8,那我只能自己找解决办法: 打开终端输入: ...

  4. LocationActivity

    package com.baidu.location.demo; import com.baidu.baidulocationdemo.R;import com.baidu.location.BDLo ...

  5. iOS文件和目录操作,iOS文件操作,NSFileManager使用文件操作:

    NSFileManager常用的文件方法: -(NSData*)contentsAtPath:path 从一个文件中读取数据 -(BOLL)createFileAtPath:path contents ...

  6. tcp与http的区别

    1.TCP连接 手机能够使用联网功能是因为手机底层实现了TCP/IP协议,可以使手机终端通过无线网络建立TCP连接.TCP协议可以对上层网络提供接口,使上层网络数据的传输建立在“无差别”的网络之上. ...

  7. Red Hat快捷键操作

    Red Hat快捷键操作 .使用虚拟控制台 登录后按“Alt+F2”键可以看到“login:”提示符, 这就是第二个虚拟控制台. 一般新安装的Linux有四个虚拟控制台, 可以用“Alt+F1”到“A ...

  8. DataGridView使用技巧十三:点击列头实现升序和降序排序

    DataGridView 列有三种排序模式.每一列的排序模式是通过该列的 SortMode 属性指定的,该属性可以设置为以下的 DataGridViewColumnSortMode 枚举值之一. Da ...

  9. Cracking the coding interview--Q2.5

    题目 原文: Given a circular linked list, implement an algorithm which returns node at the beginning of t ...

  10. Rails NameError uninitialized constant class solution

    rails nameerror uninitialized constant class will occur if your rails console is not loaded with con ...