windows Ftp 操作
来源:互联网 发布:淘宝网套装春秋女装 编辑:程序博客网 时间:2024/06/06 08:50
其实 在msdn中就有现成的,拷贝下稍微修改下就成了,需要注意的是
1、目录问题
pConnect->GetCurrentDirectory(dir); 访问路径后 调用此函数获取路径一定是根目录“/”;我们可以直接设置目录,注意此时就不能把前面的<pre name="code" class="cpp">ftp://ftp.microsoft.com 包含上去了;
2、获取文件失败<pre name="code" class="cpp">pConnect->GetFile,首先看下第三个参数,如果设置成true,即不覆盖,那么如果本地路径下已经存在此文件,那么就会返回失败,所以防止这种错误,设置成false;
void CTestFtpDlg::FtpVist(){CInternetSession sess(_T("My FTP Session"));CFtpConnection* pConnect = NULL;try{// Request a connection to ftp.microsoft.com. Default // parameters mean that we'll try with username = ANONYMOUS // and password set to the machine name @ domain namepConnect = sess.GetFtpConnection(_T("ftp.microsoft.com"));// use a file find object to enumerate filesCFtpFileFind finder(pConnect);// start loopingBOOL bWorking = finder.FindFile(_T("*"));CString str;while (bWorking){bWorking = finder.FindNextFile();//_tprintf_s(_T("%s\n"), (LPCTSTR)finder.GetFileURL());str += (LPCTSTR)finder.GetFileURL();str += finder.GetFileName();str += L"\r\n";}MessageBox(str, L"123");CString dir;pConnect->GetCurrentDirectory(dir); ///< 此时为根目录 “/”,就是所在设备的目录,而不是 ftp://ftp.microsoft.com/bussys/Clients/pConnect->SetCurrentDirectory(L"/bussys/Clients/");pConnect->GetCurrentDirectory(dir);#if 0if (0 == pConnect->GetFile(L"/bussys/Clients/update.txt", L"D:\\cwqUpdate.txt", false)){MessageBox(L"error", L"c");}#elseif (0 == pConnect->GetFile(L"update.txt", L"D:\\cwqUpdate.txt", false)) ///< 即使有也覆盖{MessageBox(L"error", L"c");}#endif}catch (CInternetException* pEx){TCHAR sz[1024];pEx->GetErrorMessage(sz, 1024);_tprintf_s(_T("ERROR! %s\n"), sz);pEx->Delete();}// if the connection is open, close it if (pConnect != NULL){pConnect->Close();delete pConnect;}}
0 0
- windows Ftp 操作
- Windows下FTP自动登录操作脚本
- windows下使用bat脚本操作ftp服务器
- ftp操作
- FTP操作
- ftp操作
- Ftp操作
- 【python FTP】python操作FTP
- windows python 访问ftp
- windows-ftp-bat
- windows ftp批处理
- Filezilla 搭建windows FTP
- Windows下FTP命令
- windows ftp 上传下载文件
- windows 2003建立ftp
- windows FTP上传
- Windows 7 搭建FTP
- windows ftp Linux
- html button
- android应用程序如何调用支付宝接口
- git 常用命令
- Hadoop#1:数据文件
- javascript--闭包性质以及JS垃圾回收器
- windows Ftp 操作
- 网络基本功系列:细说网络那些事儿
- 学习日志 2015/01/28
- 重写PagerAdapter与FragmentPagerAdapter
- 使用 soapUI 测试 REST 服务
- 有关IPv4的ToS字段
- 记 路由器TP-link WR1043ND-V2 刷Openwrt后 非TTl 修砖经历
- UVA 10911
- 课程设计之霍夫曼编码