In the programming of VC , we often use some of the features on the Internet, such as FTP, WWW and other functions. In my multi-year programming process, some small experiences have passed, write out with you, please advise. I conveniently realize the function of the FTP function in VC , this is only a small test program, and many features can be extended through this program, such as implementing the function of downloading files in the FTP function. Run this applet after dialing, you can implement this function.
Create a dialog-based application in VC , you need to note that when you create this project, you must select Windows Sockets. The structure of the dialog created is as shown in the figure, and adds the #include 'AFXINET.H' header file in the file of the dialog class. Then add the following function in the file of the dialog box. This function is the event that tap the Send-Button button. It is mainly the function of the FTP function to transfer files. The files you want to pass in this project should be placed in this project. If you put it elsewhere, you can change it.
Void cftptestdlg :: OnsendButton ()
{
CString host;
m_hostedit.getWindowText (Host);
// m_hostedit is a naming of FTP Host: Edit control in the dialog
CSTRING User;
M_Useredit.GetWindowText (user);
// m_useredit is the name of User: Edit control in the dialog
Cstring password;
m_passwordedit.getWindowText (Password);
// m_passwordedit is the name of the Password: edit control in the dialog
CSTRING FILENAME;
m_fileEdit.GetWindowText (filename);
// m_fileEdit is a name of Sendfile: Edit control in the conversation
Trace (':% s:% s:% s:% s / n', Host,
User, Password, FileName;
CinternetSession session
(AfxGetApp () -> m_pszappname);
CFTPConnection * PConn = NULL;
PConn = session.GetftPConnection
Host, User, Password;
IF (PCONN) {
IF (! PCONN-> Putfile (filename, filename) {
MessageBox ('transfer file failed ??');
} else {
MessageBox ('transfer file success!');
}
PCONN-> Close ();
DELETE PCONN;
session.close ();
} else {
MessageBox ('Cannot Connect');
}
}
This application uses a Chinese 95 operating system to develop, compile and run on VC 5.0.