使用MFC WinInet进行FTP中文件的简单上传和下载功能
建立基于对话框的MFC应用程序CMfcFtpWinInetDlg:
1、首先Dlg类中包含头文件 #include "afxinet.h"
2、添加成员变量:
1
2 3 |
private:
CFtpConnection* m_pFtpConnection; CInternetSession m_Session; |
3、在OnInitDialog中加入Ftp连接代码:
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 m_pFtpConnection = m_Session.GetFtpConnection(_T("localhost"), _T("Manager"), _T("kingview"), INTERNET_INVALID_PORT_NUMBER); |
4、在OK和Cancel按钮中加入关闭Ftp连接代码:
1
2 3 4 5 6 |
// TODO: Add your control notification handler code here
m_Session.Close(); m_pFtpConnection->Close(); if(m_pFtpConnection != NULL) |
5、添加Upload以及Download按钮代码:
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 if(Finder.FindFile(_T("F:\\hot.gif"))==TRUE) BOOL bUploaded = m_pFtpConnection->PutFile( _T("F:\\hot.gif"), AfxMessageBox(_T("Uploaded Successfully")); void CMfcFtpWinInetDlg::OnBnClickedBtnDownload() |
API参数说明,请参考MSDN。
最新文章
- MYsql 数据库密码忘记(Linux)
- 剑指Offer面试题:2.二维数组中的查找
- 学习笔记(二)——MVC扩展(渲染视图)
- B窗体继承于A窗体,B启动:问题点
- 新冲刺Sprint3(第七天)
- ReflectionHelper
- 对Oracle10g rac srvctl命令使用理解
- [转]遍历windows服务
- vs代码段快捷键设置
- 【iBoard电子学堂开发板例程】【12个 stm32 例程发布】
- 95秀-弹窗+listview+动画 示例
- Linux_install mod_ssl openssl apache
- iphone开发小记
- Java--最大子序列和实现
- Android 添加水印, 以及屏幕存取
- 安装jdk设置环境变量(win10)
- Elasticsearch System Call Filters Failed to Install
- 025 SSM简单搭建
- Mongodb 分组查询例子
- print($arr,true)的参数true表示将$arr的值返会,而不是打印
热门文章
- 更新yum源却忘了生成缓存 造成每次启动机器报:the package list needs to be rebuilt
- removeChildByTag、schedule、schedule_selector
- JVM Inline
- electron 的跳转
- VBA学习笔记(6)--抽取第一列中叫“虹虹”的个人信息
- ios开发之修改 UITableview 滚动条颜色的方法
- 一款纯css实现的漂亮导航
- 线程安全,有状态,无状态的对象<;转>;
- u-boot中网口处理--硬件部分
- 第一次使用bootstrap3做的响应式网站