Using the WinInet function to simply implement the FTP client __ function

Source: Internet
Author: User
Tags ftp client
#include <WinInet.h> #pragma comment (lib, "WinInet.lib")
BOOL Ftpupload (const string& strftphost, int nport, const string &struser, const string &strpwd, const STRI ng& strlocalfile, const string& strftpfile, String &strmsg) {BOOL dres,pres; Hinternet hinternet; Hinternet Hconnect;
const char *pftphost = STRFTPHOST.C_STR (); if (nport==0) {nport = internet_default_ftp_port} const char *pftpuser = STRUSER.C_STR (); const char *PFTPPWD = STRPWD.C_STR (); const char *plocalfile = STRLOCALFILE.C_STR (); const char *pftpfile = STRFTPFILE.C_STR ();
Hinternet = InternetOpen ("Dataclient", Internet_open_type_direct,null, NULL, internet_flag_no_cache_write); if (NULL = = hinternet) {//printf ("InternetOpen error:%d", GetLastError ()); STRMSG = "InternetOpen Error"; return false; }
Hconnect = InternetConnect (hinternet, Pftphost, Nport, Pftpuser, Pftppwd, Internet_service_ftp, INTERNET_FLAG_EXISTING _connect | | internet_flag_passive,0); if (NULL = = hinternet) {//printf ("InternetConnect error:%d", GetLastError ()); STRMSG = "InternetConnect Error"; InternetCloseHandle (hinternet); return false; }
Dres = FtpGetFile (Hconnect, "./usera/123.txt", "D:\\ftp123.txt", FALSE, File_attribute_archive, Ftp_transfer_type_ UNKNOWN, 0); if (Dres = = 0)//{//printf ("FtpGetFile Error:", GetLastError ()); //}
PRes = FtpPutFile (hconnect,plocalfile,pftpfile,ftp_transfer_type_binary,0); InternetCloseHandle (Hconnect); InternetCloseHandle (hinternet);
if (pres==0) {//printf ("upload file failed.) "); STRMSG = "FtpPutFile Error"; return false; }
Strmsg= "last Success"; return true; }

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.