CInternetSession* m_pInetSession;
 CFtpConnection*   m_pFtpConnection;

//连接服务器的函数

BOOL CftpClientDlg::connnect()
{
 m_pInetSession = new CInternetSession( AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
 try{
  m_pFtpConnection = m_pInetSession->GetFtpConnection(L"127.0.0.1",L"chentongxin",L"tongxin",21);
  AfxMessageBox(L"服务器连接成功");
 }
 catch(CInternetException *pEx){
  
  TCHAR szError[1024] = {0};
  if(pEx->GetErrorMessage(szError,1024))
   AfxMessageBox(szError);
  else
   AfxMessageBox(L"服务器连接失败");
  pEx->Delete();
  m_pFtpConnection = NULL;

return FALSE;
 }
 return TRUE;
}

//上传文件
BOOL CftpClientDlg::putFile()
{
 if(m_pFtpConnection->PutFile(_T("e:/test.txt"),_T("test.txt"))){
  //第一个参数为本地文件的地址,第二个为服务器端文件的地址
  AfxMessageBox(_T("发送成功!"));
  return TRUE;
 }
 else{
  AfxMessageBox(_T("发送失败!"));
  return FALSE;
 }
}

//下载文件
BOOL CftpClientDlg::getFile()
{
 if(m_pFtpConnection->GetFile(_T("afa.txt"),_T("e:/a.txt"))){
  //第一个参数为本地文件的地址,第二个为服务器端文件的地址
  AfxMessageBox(_T("下载成功!"));
  return TRUE;
 }
 else{
  AfxMessageBox(_T("下载失败!"));
  return FALSE;
 }
 return TRUE;
}

//关闭连接
BOOL CftpClientDlg::disconnect()
{
 if(m_pFtpConnection != NULL)
 {
  m_pFtpConnection->Close();
  delete m_pFtpConnection;
 }
 delete m_pInetSession;
 return TRUE;
}

MFC连接ftp服务器的更多相关文章

  1. 【FTP】C# System.Net.FtpClient库连接ftp服务器(上传文件)

    如果自己单枪匹马写一个连接ftp服务器代码那是相当恐怖的(socket通信),有一个评价较高的dll库可以供我们使用. 那就是System.Net.FtpClient,链接地址:https://net ...

  2. 【FTP】C# System.Net.FtpClient库连接ftp服务器(下载文件)

    如果自己单枪匹马写一个连接ftp服务器代码那是相当恐怖的(socket通信),有一个评价较高的dll库可以供我们使用. 那就是System.Net.FtpClient,链接地址:https://net ...

  3. MFC 遍历FTP服务器目录相关

    CInternetSession* pSession; pSession = new CInternetSession;  //构造新的连接 CFtpConnection* pFtpCon; pFtp ...

  4. java 无法连接ftp服务器(500 OOPS: cannot change directory)

    在使用java连接ftp服务器时可能会出现无法连接的情况,检查代码是没有错误的,这时就应该考虑一下服务器端的情况了: 首先用在本地打开命令窗口,输入:ftp ftp服务器IP,窗口会提示你输入用户名密 ...

  5. linux下常用FTP命令 1. 连接ftp服务器

    1. 连接ftp服务器 格式:ftp [hostname| ip-address] a)在linux命令行下输入: ftp 192.168.1.1 b)服务器询问你用户名和密码,分别输入用户名和相应密 ...

  6. linux下常用FTP命令 1. 连接ftp服务器[转]

    1. 连接ftp服务器 格式:ftp [hostname| ip-address]a)在linux命令行下输入: ftp 192.168.1.1 b)服务器询问你用户名和密码,分别输入用户名和相应密码 ...

  7. 连接ftp服务器 JDK 1.7

    import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.F ...

  8. 【VS2019】Web项目发布时提示无法连接FTP服务器

    使用 Visual Studio 2019 时出现的问题 环境:win10 ltsc 场景 发布Web项目到FTP时 失败,并提示 _无法打开网站"ftp://...".未安装与 ...

  9. 常用FTP命令 1. 连接ftp服务器

    1. 连接ftp服务器 格式:ftp [hostname| ip-address]a)在linux命令行下输入: ftp 192.168.1.1 b)服务器询问你用户名和密码,分别输入用户名和相应密码 ...

随机推荐

  1. HTML基本标签大全

    HTML标签 <h#></h#>标题标签<hr/>水平线,单标记<p></p>段落标签&nbsp 空格<i></i ...

  2. 创建简单的ajax对象

    oAjax=               oAjax=                     oAjax.open('GET', url,                               ...

  3. C# System.AppDomain类

    进程是存在独立的内存和资源的,但是AppDomain仅仅是逻辑上的一种抽象.一个process可以存在多个AppDomain.各个AppDomain之间的数据时相互独立的.一个线程可以穿梭多个AppD ...

  4. android 中FragmentActivity中模拟返回键返回上一个Activity效果

    FragmentTransaction中先加入一个Fragment,这个Fragment就是当前要显示的Fragment, 当通过事件触发显示第二个Fragment时,在加入第二个Fragment并调 ...

  5. POJ 1094 Sorting It All Out (拓扑排序) - from lanshui_Yang

    Description An ascending sorted sequence of distinct values is one in which some form of a less-than ...

  6. hdu 4620 Fruit Ninja Extreme

    Fruit Ninja Extreme Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  7. css案例学习之div a实现立体菜单

    效果 代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...

  8. ubuntu 包维护

    gnats == bug; tox = tales xillia ubuntu回显当前目录

  9. java web分页查询初试

    ssh2分页查询初试,放着记录学习一下. entity:student.java: package com.zte.entity; /** * 数据持久化,跟数据库的的相应的表的字段是对应的. * * ...

  10. lua 类实现

    Class={}; Class.classList={}; --保存所有已经定义过的类 --类的类型: 类和接口, 接口也是一种类 Class.TYPE_CLASS="Class" ...