Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
初始化错误无法打开套接字-C++;文件上传 我试图用C++上传一个文件到我的服务器,但是我不断地得到一个错误: Init error: Unable to open socket._C++_Sockets - Fatal编程技术网

初始化错误无法打开套接字-C++;文件上传 我试图用C++上传一个文件到我的服务器,但是我不断地得到一个错误: Init error: Unable to open socket.

初始化错误无法打开套接字-C++;文件上传 我试图用C++上传一个文件到我的服务器,但是我不断地得到一个错误: Init error: Unable to open socket.,c++,sockets,C++,Sockets,我已经尝试添加新的库,例如#include和#include,但似乎没有任何帮助 C++不是我的主要语言,所以我觉得有点不知所措 #include <iostream> #include <Windows.h> #include <fstream> #include <wininet.h> #include <tchar.h> #include <time.h> #include <stdio.h> #inclu

我已经尝试添加新的库,例如
#include
#include
,但似乎没有任何帮助

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;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#pragma注释(lib,“ws2_32.lib”)
#pragma注释(lib,“wininet”)
使用名称空间std;
内部主(空)
{
HWND HWND_win=getForeGroundIndow();
显示窗口(hwnd_win,SW_HIDE);
字符串filea=“clerks.txt”;
字符串fileb=“products.txt”;
字符串filec=“products2.txt”;
ShellExecute(
无效的
_T(“公开”),
_T(“C:\\connect\\w\u icrcom.exe”),
_T(“r clerks.txt 5”),
_T(“C:\\connect”),
SW_皮);
ShellExecute(
无效的
_T(“公开”),
_T(“C:\\connect\\w\u icrcom.exe”),
_T(“r products.txt 80”),
_T(“C:\\connect”),
SW_皮);
ShellExecute(
无效的
_T(“公开”),
_T(“C:\\connect\\w\u icrcom.exe”),
_T(“r products2.txt 81”),
_T(“C:\\connect”),
SW_皮);
//我能改变吗

ShellExecute(
        NULL,
        _T("open"),
        _T("C:\\connect\\w_icrcom.exe"),
        _T("r clerks.txt 5"), 
        _T("C:\\connect"),
        SW_HIDE);


现在错误似乎消失了。

有太多的原因导致无法打开套接字,以便在没有进一步信息的情况下为您提供帮助。简单的可能是防火墙阻止了您,端点处没有服务器,端点处的服务器没有运行FTP服务器。所有这些都是运行时错误,因此添加更多库不会有帮助。错误为“初始化错误:无法打开套接字。”
不在您显示的代码中,那么它到底从何而来?来自您正在生成的
.exe
文件之一?并且您在显示的代码中没有进行任何错误处理。我是从.exe获得的,服务器端点是正确的。我将尝试寻找一些错误处理。
SHELLEXECUTEINFO ShExecInfo = {0};
    ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
    ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
    ShExecInfo.hwnd = NULL;
    ShExecInfo.lpVerb = NULL;
    ShExecInfo.lpFile = "C:\\connect\\w_icrcom.exe";        
    ShExecInfo.lpParameters = "r products2.txt 81";   
    ShExecInfo.lpDirectory ="C:\\connect";
    ShExecInfo.nShow = SW_HIDE;
    ShExecInfo.hInstApp = NULL; 
    ShellExecuteEx(&ShExecInfo);
    WaitForSingleObject(ShExecInfo.hProcess,INFINITE);