需要使用Wininet函数的帮助吗 我在C++编程,我想上传一个文件到我的Web服务器,我已经用下面的代码做了: #include "stdafx.h" #include <windows.h> #include <wininet.h> #pragma comment(lib, "wininet") int _tmain(int argc, _TCHAR* argv[]) { HINTERNET hInternet; HINTERNET hFtp; hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL,NULL,0); hFtp = InternetConnect(hInternet, L"ftp.freetzi.com", INTERNET_DEFAULT_FTP_PORT, L"myuser.freetzi.com", "mypassword", INTERNET_SERVICE_FTP, 0, 0); FtpPutFile(hFtp, L"C:\\deneme.txt", L"coolName.txt", FTP_TRANSFER_TYPE_BINARY, 0); if ( FtpPutFile(hFtp, L"C:\\deneme.txt", L"coolName.txt", FTP_TRANSFER_TYPE_BINARY, 0) ) { MessageBox(NULL, L"Upload Successful.", L"Title", NULL); } else { //This is the message I get... MessageBox(NULL, L"Upload Failed.", L"Title", NULL); } InternetCloseHandle(hFtp); InternetCloseHandle(hInternet); return 0; }

需要使用Wininet函数的帮助吗 我在C++编程,我想上传一个文件到我的Web服务器,我已经用下面的代码做了: #include "stdafx.h" #include <windows.h> #include <wininet.h> #pragma comment(lib, "wininet") int _tmain(int argc, _TCHAR* argv[]) { HINTERNET hInternet; HINTERNET hFtp; hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL,NULL,0); hFtp = InternetConnect(hInternet, L"ftp.freetzi.com", INTERNET_DEFAULT_FTP_PORT, L"myuser.freetzi.com", "mypassword", INTERNET_SERVICE_FTP, 0, 0); FtpPutFile(hFtp, L"C:\\deneme.txt", L"coolName.txt", FTP_TRANSFER_TYPE_BINARY, 0); if ( FtpPutFile(hFtp, L"C:\\deneme.txt", L"coolName.txt", FTP_TRANSFER_TYPE_BINARY, 0) ) { MessageBox(NULL, L"Upload Successful.", L"Title", NULL); } else { //This is the message I get... MessageBox(NULL, L"Upload Failed.", L"Title", NULL); } InternetCloseHandle(hFtp); InternetCloseHandle(hInternet); return 0; },c++,function,upload,ftp,wininet,C++,Function,Upload,Ftp,Wininet,但是由于这个程序将被很多人使用,我找不到一种方法来重命名上传的文件coolname.txt如果目标文件已经存在,上面的代码将覆盖旧数据,并重写新使用的数据2次或更多次 我试过: /public_html/log.txt+std::to_stringrand 二,。功能:- generateFileName std::字符串常量和目录, std::string const和rootName, std::字符串常量和扩展名 { 标准::ostringstream结果; 结果:填写“0”; 结果您可以

但是由于这个程序将被很多人使用,我找不到一种方法来重命名上传的文件coolname.txt如果目标文件已经存在,上面的代码将覆盖旧数据,并重写新使用的数据2次或更多次

我试过:

/public_html/log.txt+std::to_stringrand 二,。功能:-

generateFileName std::字符串常量和目录, std::string const和rootName, std::字符串常量和扩展名 { 标准::ostringstream结果; 结果:填写“0”;
结果您可以将输出文件名定义为变量

#include <iostream>
#include <string>
#include <stdio.h>
#include <time.h>

// Get current date/time, format is YYYY-MM-DD.HH:mm:ss
const std::string currentDateTime() {
    time_t     now = time(0);
    struct tm  tstruct;
    char       buf[80];
    tstruct = *localtime(&now);
    // Visit http://en.cppreference.com/w/cpp/chrono/c/strftime
    // for more information about date/time format
    strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);

    return buf;
}

int main() {
    std::cout << "currentDateTime()=" << currentDateTime() << std::endl;
    getchar();  // wait for keyboard input
}
将文件名定义为变量,我们必须在其中附加当前时间戳和文件名

最后,您的文件名将是coolName_2014.06.25.07.08.08.txt

我希望这对你有帮助