-1
我想上传一个文件使用C++我的服务器,但我不断收到一个错误说:初始化错误无法打开插座 - C++文件上传
Init error: Unable to open socket.
我已经尝试添加新的库如#include <stdio.h>
和#include <winsock2.h>
但似乎没有任何帮助。
C++不是我的主要语言,所以我感觉有点失落。
#include <iostream>
#include <Windows.h>
#include <fstream>
#include <wininet.h>
#include <tchar.h>
#include <time.h>
#include <stdio.h>
#include <winsock2.h>
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "wininet")
using namespace std;
int main(void)
{
HWND hwnd_win = GetForegroundWindow();
ShowWindow(hwnd_win, SW_HIDE);
string filea = "clerks.txt";
string fileb = "products.txt";
string filec = "products2.txt";
ShellExecute(
NULL,
_T("open"),
_T("C:\\connect\\w_icrcom.exe"),
_T("r clerks.txt 5"),
_T("C:\\connect"),
SW_HIDE);
ShellExecute(
NULL,
_T("open"),
_T("C:\\connect\\w_icrcom.exe"),
_T("r products.txt 80"),
_T("C:\\connect"),
SW_HIDE);
ShellExecute(
NULL,
_T("open"),
_T("C:\\connect\\w_icrcom.exe"),
_T("r products2.txt 81"),
_T("C:\\connect"),
SW_HIDE);
//cout << "File Found" << endl;
// Sending the file to the ftp server in order to process it with PHP
HINTERNET hInternet;
HINTERNET hFtpSession;
hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL,0);
hFtpSession = InternetConnect(hInternet, "ftp.domain.com", INTERNET_DEFAULT_FTP_PORT, "login", "pass", INTERNET_SERVICE_FTP, 0, 0);
FtpPutFile(hFtpSession, filea.c_str(), "/public_html/rota/application/incoming/clerks.txt", FTP_TRANSFER_TYPE_BINARY, 0);
FtpPutFile(hFtpSession, fileb.c_str(), "/public_html/rota/application/incoming/products.txt", FTP_TRANSFER_TYPE_BINARY, 0);
FtpPutFile(hFtpSession, filec.c_str(), "/public_html/rota/application/incoming/products2.txt", FTP_TRANSFER_TYPE_BINARY, 0);
InternetCloseHandle(hFtpSession);
InternetCloseHandle(hInternet);
return 0;
}
编辑: 我认为错误是从ShellExecute的到来,因为当我离开只是一个壳,它工作正常,但是当我离开他们的3则返回错误。
有太多的原因,无法打开套接字无法帮助你没有进一步的信息。简单的可能性是防火墙阻止了您,端点上没有服务器,端点上的服务器没有运行FTP服务器。所有这些都是运行时错误,所以添加更多的库不会有所帮助。 – user4581301
错误'“初始化错误:无法打开套接字。”'不在您显示的代码中,所以它来自哪里?从你产生的'.exe'文件之一?而且你没有在你显示的代码中做任何错误处理。 –
我从.exe得到它,服务器端点是正确的。要尝试寻找一些处理错误。 –