65,206
社区成员
发帖
与我相关
我的任务
分享string remoteName = "192.168.1.11";
string filename = "c:\\Log.txt";
string userName = "test";
string userPass = "123456";
//string path = "/xx/";
string targetFileName = "/xx/aa";
HINTERNET hSession = InternetOpenA("InetURL/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if(hSession != NULL){
HINTERNET hConnection;
hConnection = InternetConnectA(hSession, remoteName.c_str(), INTERNET_DEFAULT_FTP_PORT, userName.c_str(), userPass.c_str(),INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
if(hConnection != NULL){
//unsigned long lpdwCurrentDirectory = MAX_PATH;
//unsigned long lpdwCurrentDirectory2 = MAX_PATH;
//LPSTR lpszCurrentDirectory;
//char lpszCurrentDirectory[MAX_PATH];
//char lpszCurrentDirectory2[MAX_PATH];
//BOOL success = FtpGetCurrentDirectoryA(hConnection,lpszCurrentDirectory,&lpdwCurrentDirectory);
//std::cout<<"lpszCurrentDirectory"<<lpszCurrentDirectory<<std::endl;
//stringstream ss;
//ss<<lpszCurrentDirectory<<path;
//path = ss.str();
//string path = string(lpszCurrentDirectory)+path;
//std::cout<<"succ:"<<success<<"path is:"<<path<<std::endl;
//std::cout<<"dic:"<<lpszCurrentDirectory<<std::endl;
//success = FtpSetCurrentDirectoryA(hConnection, path.c_str());
//std::cout<<"succ:"<<success<<std::endl;
success = FtpPutFileA(hConnection, filename.c_str(), targetFileName.c_str(), FTP_TRANSFER_TYPE_ASCII, 0);
int rc = GetLastError();
std::cout<<"rc is:"<<rc<<std::endl;
if(rc == ERROR_INTERNET_EXTENDED_ERROR){
char szError[1024];
DWORD dwErrorSize = 1024;
DWORD dwLastErrorMsg;
InternetGetLastResponseInfoA(&dwLastErrorMsg,szError,&dwErrorSize);
std::cout<<"szError:"<<szError<<std::endl;
}