// Testtmpmfc. cpp: defines the entry point of the console application.
# Include "stdafx. H"
# Include "testtmpmfc. H"
# Ifdef _ debug
# Define new debug_new
# Endif
# Include <string>
# Include <iostream>
# Include <afxinet. h>
# Include <windows. h>
// Unique application object
Cwinapp theapp;
Using namespace STD;
Int _ tmain (INT argc, tchar * argv [], tchar * envp [])
...{
// Test FTP
Int nretcode = 0;
// Initialize the MFC and display an error upon failure
If (! Afxwininit (: getmodulehandle (null), null,: getcommandline (), 0 ))
...{
// Todo: Change the error code to meet your needs.
_ Tprintf (_ T ("Fatal error: MFC initialization failed "));
Nretcode = 1;
}
Else
...{
// Todo: write code for the Application behavior here.
}
String serveripstr = "10.132.143.161 ";
String usrnamestr = "movie ";
String usrpwstr = "movie ";
String portstr = "21 ";
String serverfile = "/A/a.txt ";
String serverpath = "/";
String localfile = "./A/a.txt ";
Cinternetsession SESSION ("Update session ");
Cftpconnection * pftpconnection = NULL;
Try
...{
Pftpconnection = session. getftpconnection (serveripstr. c_str (), usrnamestr. c_str (), usrpwstr. c_str (), atoi (portstr. c_str ()));
If (pftpconnection = NULL)
Return false;
Bool B = pftpconnection-> setcurrentdirectory (serverpath. c_str ());
If (B = false)
...{
Afxmessagebox ("set current dir error ");
Return false;
}
// Create a directory
Createdirectory ("./A/", null );
// Check and delete the file
Win32_find_data findfiledata;
Handle hfind;
Hfind = findfirstfile (localfile. c_str (), & findfiledata );
If (hfind! = Invalid_handle_value)
...{
Deletefile (localfile. c_str ());
Cout <"find such a file" <Endl;
Findclose (hfind );
}
B = pftpconnection-> GetFile (serverfile. c_str (), localfile. c_str ());
If (B = false)
...{
Int error = getlasterror ();
Cstring strerror;
Strerror. Format ("download file error: % d", error );
Afxmessagebox (strerror );
Pftpconnection-> close ();
Return false;
}
Pftpconnection-> close ();
} Catch (cinternetexception * PEX )...{
Tchar SZ [1024];
Pex-& gt; geterrormessage (SZ, 1024 );
Printf ("error! % S ", SZ );
Pex-> Delete ();
Return false;
}
Return nretcode;
}