当前位置:网站首页>MFC FTP创建多级文件夹、上传文件到FTP指定目录
MFC FTP创建多级文件夹、上传文件到FTP指定目录
2022-07-27 12:51:00 【sam-zy】
1.FTP创建多级文件夹
//FTP创建多级文件夹
BOOL CFTPDlg::CreateFolderToFtp(CString strFtpPath)
{
try
{
CStringArray Dirs;
ParseCString(strFtpPath, Dirs, '/'); //字符分割
CString CurDir =_T("/");
for (int i = 1; i < Dirs.GetCount(); i++)
{
CurDir = CurDir + Dirs[i] + _T("/"); //一层一层创建
BOOL ret = m_pFtpConnection->CreateDirectory(CurDir);
}
}
catch (CInternetException* pEx)
{
TCHAR szError[100];
if (pEx->GetErrorMessage(szError, 100))
{
AfxMessageBox(szError);
}
pEx->Delete();
m_pFtpConnection = NULL;
if (m_pInetSession)
{
m_pInetSession->Close();
m_pInetSession = NULL;
}
return FALSE;
}
return TRUE;
}
//测试按钮-1
void CFTPDlg::OnBnClickedDownload2()
{
CreateFolderToFtp(TEXT("/文件夹1/文件夹2/文件夹3")); //创建文件夹
}

2.上传文件
// 上传图片
void CFTPDlg::UpFileImage(CString ImagePath, CString ImageName)
{
try
{
Printf1* Atf_Printf1 = (Printf1*)GetParent();
CString strMsg;
CStringArray Dirs;
ParseCString(ImagePath, Dirs, ':'); //字符分割(获取盘符后面的路径)
CreateFolderToFtp(Dirs[1]); //FTP创建目录
if (m_pFtpConnection->PutFile(ImagePath + ImageName, Dirs[1] +ImageName))//上传图片
{
strMsg.Format(_T("上传图片成功 strRemoteFile:%s\r\n"), Dirs[1] + ImageName);
Atf_Printf1->Printf1ByValue(strMsg);
DeleteFile(ImagePath + ImageName);//删除图片
strMsg.Format(_T("删除图片成功 strLocalFile:%s\r\n"), ImagePath + ImageName);
Atf_Printf1->Printf1ByValue(strMsg);
}
else
{
strMsg.Format(_T("上传文件失败,请检查您的FTP服务器是否正确\r\n"));
}
}
catch ()
{
}
}
执行结果:
上传图片成功 strRemoteFile:/Image/Ori/2022-07-26/12/YT5636713886474.jpg
删除图片成功 strLocalFile:D:/Image/Ori/2022-07-26/12/YT5636713886474.jpg
边栏推荐
- Application for the latest version of Pan domain name certificate
- Firefox 103 release, faster and more secure
- 《数字经济 科技向善》大咖对谈干货来啦
- Initializing database error after reinstalling MySQL
- libevent 之 evconnlistener_new_bind
- From the perspective of it, the CIO of B2B industry talks about how to change from "cost center" to "growth center"?
- PAT乙级 1109 擅长C(详解)
- Feign的两个调用处理器
- Eccv2022 | Ru & Google proposed to use clip for zero shot target detection!
- 元素的层级
猜你喜欢

v-text

Will saffron become a safe and effective natural therapy for patients with arthritis?

Application of responsibility chain model in transfer accurate valuation

How to debug JNI program

v-text

B站713故障后的多活容灾建设|TakinTalks大咖分享

Eccv2022 | Ru & Google proposed to use clip for zero shot target detection!

Jesd204b debugging notes (practical version)

开源项目丨Taier1.2版本发布,新增工作流、租户绑定简化等多项功能

libevent 之 evconnlistener_new_bind
随机推荐
高度塌陷最终解决方案(无副作用)
Write a program, accept a string consisting of letters, numbers and spaces, and a character, and then output the number of characters in the input string. Case insensitive.
Dichotomy queries values in an array
v-text
592. Fraction addition and subtraction: introduction to expression calculation
uniapp防止连续点击出错
Pat class B 1109 good at C (detailed)
Poj1548 robots [bipartite graph minimum path coverage]
滑环设备怎么进行维护
feign client三个客户端的自动装配
Baoli food listed on Shanghai Stock Exchange: annual revenue of 1.578 billion, market value of 5.8 billion
初学者入门:使用WordPress搭建一个专属自己的博客
Seata 在蚂蚁国际银行业务的落地实践
四大线程池简析
文本样式
字节跳动的 Flink OLAP 作业调度和查询执行优化实践
Relative positioning
PAT乙级 1109 擅长C(详解)
滑环使用如何固定
Method of changing thread state