Este codigo consigue subir el archivo a un ftp que monte en mi pc, pero al probarlo con
Hostinger no hace nada...
Alguna explicacion logica?
Hostinger no hace nada...
Alguna explicacion logica?
Código [Seleccionar]
#include "string.h"
#include <iostream>
#include <windows.h>
#include <wininet.h>
using namespace std;
#pragma comment(lib,"Wininet.lib")
#include <windows.h>
#include <iostream>
#include <fstream>
#define ID_MYAPP 1
using namespace std;
long lFileSize = 0;
long nSumBytes = 0;
void GetFileName (char* szSource)
{
char* ptr;
for (ptr = &szSource [strlen (szSource)]; *ptr != '\\'; ptr--);
ptr++;
int i;
for (i = 0; *ptr != '\0';ptr++,i++)
szSource[i] = *ptr;
szSource [i] = '\0';
}
int main (int argc, char* argv [])
{
cout << "File Uploading Utility :- " << endl;
HINTERNET hInternet = NULL, hConnection = NULL;
hInternet = InternetOpen(L"Title", 0, NULL, NULL, 0);
if (hInternet == NULL)
{
cout << "Error in opening connection" ;
return 0;
}
hConnection = InternetConnect (hInternet, L"31.170.165.195", 21, L"usuario", L"password", INTERNET_SERVICE_FTP, INTERNET_FLAG_ASYNC, ID_MYAPP);
if (hConnection != NULL)
{
cout << "Connection Established\n";
}
else
{
InternetCloseHandle(hInternet);
}
HINTERNET hFile = NULL;
hFile = FtpOpenFile(hConnection, L"\\archivo remoto", GENERIC_WRITE, FTP_TRANSFER_TYPE_BINARY, 0);
HANDLE hLocalFile = NULL;
hLocalFile = CreateFile (L"archivo local", GENERIC_READ , 0, NULL,
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hLocalFile == INVALID_HANDLE_VALUE) {
cout << "Please check the file name and path" << endl;
return 0;
}
lFileSize = GetFileSize (hLocalFile, NULL) ;
char *inBuffer = new char [lFileSize];
BOOL bResult;
DWORD nBytesRead;
DWORD nBytesToReadWrite = 512; //lFileSize;
DWORD dwError;
DWORD nBytesWritten = 0;
DWORD nBytesLeft = lFileSize;
do
{
if (ReadFile(hLocalFile, inBuffer, nBytesToReadWrite, &nBytesRead, NULL))
{
nSumBytes = nSumBytes + nBytesRead;
bResult = InternetWriteFile (hFile, inBuffer, (nBytesToReadWrite >= nBytesLeft ? nBytesLeft : nBytesToReadWrite), &nBytesWritten);
nBytesLeft = lFileSize - nSumBytes;
cout << "Uploading : " << (nSumBytes * 100) / (lFileSize) << "% Completed" << "\r";
}
else
{
dwError = GetLastError ();
}
} while (nSumBytes != lFileSize);
if (nSumBytes == lFileSize)
cout << "File uploaded successfully" << endl;
CloseHandle(hLocalFile);
InternetCloseHandle (hFile);
InternetCloseHandle (hConnection);
InternetCloseHandle (hInternet);
system("pause");
return 0;
}