MFC implements the download of a specified folder or file

Source: Internet
Author: User

/************************************************************************//*FTP download the specified folder or file parameter description: FtpPath ftp to download                                                        Directory or file LocalPath saved to local directory ftpaddress FTP address Ftpsuser login FTP username ftppass login FTP password SERR error message returned when error occurs */ /******************************************************************* /bool getfilefromftp (CString ftppath, CString LocalPath, CString ftpaddress, CString ftpuser, CString Ftppass, Cstri ng &serr) {CString stemp; CString slocaltemp; CString Stempftppath; CInternetSession Pinternetcon (AfxGetAppName (), 1,pre_config_internet_access); CFtpConnection *pftpcon; try {pftpcon =pinternetcon.getftpconnection (ftpaddress, Ftpuser, FtpPass); if (pFtpCon! = N ULL) {CFtpFileFind ftpfinder (Pftpcon); BOOL bwork = Ftpfinder.findfile (Ftppath), while (bwork) {bwork = Ftpfinder.findnextfile (); if (Ftpfinder.isdots ()) con Tinue;if (Ftpfinder.isdirectory ()) {//Is the directory Stemp.empty (); stemp = Ftpfinder.getfilenamE (); Stempftppath.empty (); Stempftppath = Ftppath;stempftppath + = Stemp;stempftppath + = "\\*.*"; Slocaltemp.empty (); Slocaltemp = LocalPath + stemp; CFileStatus rstatus;if (!) ( CFile::GetStatus (Slocaltemp, Rstatus))) {//folder does not exist, created if (! ( CreateDirectory ((LPCTSTR) slocaltemp, NULL))) {//create failed DWORD Derr = GetLastError (); Serr.format ("Create new directory failed: ERROR%d"), D ERR); return FALSE; }}getfilefromftp (Stempftppath, Slocaltemp, FTPAddress, Ftpuser, Ftppass, SERR);} Else{stemp.empty (); stemp = Ftpfinder.getfilename (); Slocaltemp.empty (); slocaltemp = LocalPath + "\ \" + stemp; stemp.empt Y (); stemp = Ftpfinder.getfilepath ();//cfilestatus rstatus;if (! ( CFile::GetStatus (Slocaltemp, Rstatus))) {//File not present, download if (! (Pftpcon->getfile (Stemp, Slocaltemp, True, file_attribut E_normal, Ftp_transfer_type_binary, 1)) {//download failed DWORD Derr = GetLastError (); Serr.format (_t ("Download failed: ERROR%d"), Derr); return FALSE;}      }}}ftpfinder.close ();} }catch (CInternetException * pEx) {TCHAR szerror[1024];p ex->geterrormessage (szerror,1024); Serr.format (_t ("Connection FTP failed:%s"), pEx);p ex->delete ();p Ftpcon=null;return FALSE ;} return TRUE;}

  

MFC implements the download of a specified folder or file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.