elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Uploader (WININET C++ ftp). Como subo un archivo?
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Uploader (WININET C++ ftp). Como subo un archivo?  (Leído 2,060 veces)
70N1


Desconectado Desconectado

Mensajes: 355


Ver Perfil
Uploader (WININET C++ ftp). Como subo un archivo?
« en: 5 Septiembre 2013, 18:00 pm »

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?

Código:

#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;
}


« Última modificación: 5 Septiembre 2013, 18:10 pm por 70N1 » En línea

70N1
Eternal Idol
Kernel coder
Moderador
***
Desconectado Desconectado

Mensajes: 5.937


Israel nunca torturó niños, ni lo volverá a hacer.


Ver Perfil WWW
Re: Uploader (WININET C++ ftp). Como subo un archivo?
« Respuesta #1 en: 5 Septiembre 2013, 19:41 pm »

Depuralo y fijate que devuelve cada funcion (y el GetLastError cuando corresponda).

PD. No abras mas hilos, todos son sobre lo mismo y el proximo lo borro.


En línea

La economía nunca ha sido libre: o la controla el Estado en beneficio del Pueblo o lo hacen los grandes consorcios en perjuicio de éste.
Juan Domingo Perón
70N1


Desconectado Desconectado

Mensajes: 355


Ver Perfil
Re: Uploader (WININET C++ ftp). Como subo un archivo?
« Respuesta #2 en: 6 Septiembre 2013, 01:33 am »

De aki y de alla...
Este codigo sube a la perfeccion archivos binarios a un ftp.

Código:
#include <windows.h>
#include <stdio.h>
#include <wininet.h>
#include <iostream>
using namespace std;
#pragma comment(lib,"Wininet.lib")
/*
InternetOpen - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/internetopen.asp
InternetConnect - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/internetwritefile.asp
FtpOpenFile - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/ftpopenfile.asp
InternetWriteFile - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/internetwritefile.asp
InternetCloseHandle - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/internetclosehandle.asp
*/

int main(int argc, char *argv[])
{
HINTERNET Open=InternetOpen(L"Explorador"/*user agent*/,
    0/*tipo de conexion*/,
    NULL/*nombre del proxy*/,
    NULL/*lista opcional de ip y hosts*/,
    0/*flag*/
    );
    if(Open==NULL){printf("\n[*] Error al abrir la conexion\n");return -1;}
    printf("Abriendo conexion..\n");
    
    HINTERNET Connect=InternetConnect(Open/*el handle a la sesion*/,
    L"localhost"/*la ruta*/,
    21,//INTERNET_DEFAULT_FTP_PORT/*el puerto*/,
    L"toni"/*el nombre de usuario*/,
    L"toni"/*la contraseña*/,
    INTERNET_SERVICE_FTP/*tipo de servicio*/,
    0/*flag*/,
    0);
    if(Connect==NULL){InternetCloseHandle(Open);printf("\n[*] Error al conectar con el servidor\n");getchar();return -1;}
    printf("Conexion establecida...\n");
    printf("Creando archivo...\n");
    HINTERNET OpenFile=FtpOpenFile(Connect,/*la sesion ftp*/
    L"PORFIN.EXE",/*el nombre del fichero en el servidor*/
    GENERIC_WRITE,/**tipo de acceso al archivo*/
    FTP_TRANSFER_TYPE_ASCII,/*tipo de transferencia de datos*/
    0);
    if(OpenFile==NULL){InternetCloseHandle(Open);InternetCloseHandle(Connect);printf("\n[*] Error al crear el fichero en el servidor\n");getchar();return -1;}
    printf("Subiendo archivo...\n");
    //escribimos el archivo
    




 HANDLE Archivo = CreateFile (L"c:\\texto.txt", GENERIC_READ , 0, NULL,
 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
 if (Archivo == INVALID_HANDLE_VALUE) {
cout << "Please check the file name and path" << endl;
return 0;
 }





int lFileSize;
lFileSize = GetFileSize (Archivo, NULL) ;
char *inBuffer = new char [lFileSize];
 BOOL bResult;
 DWORD nBytesRead;
 DWORD nBytesToReadWrite = 512; //lFileSize;
 DWORD dwError;
 DWORD nBytesWritten = 0;
 DWORD nBytesLeft = lFileSize;
 bool nSumBytes=0;
  do
 {
if (ReadFile(Archivo, inBuffer, nBytesToReadWrite, &nBytesRead, NULL))
{
nSumBytes = nSumBytes + nBytesRead;
bResult = InternetWriteFile (OpenFile, 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;



  
    //salimos
  
    InternetCloseHandle(Open);
    InternetCloseHandle(Connect);
    InternetCloseHandle(OpenFile);
    return 0;
}



Porsierto.... disculpa pero los post son formas diferentes de recoger datos como el ftpgetfile y ftpputfile. este codigo da un porcentaje.
« Última modificación: 6 Septiembre 2013, 01:34 am por 70N1 » En línea

70N1
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
como subo una imagen?
Sugerencias y dudas sobre el Foro
kepa27 7 2,760 Último mensaje 24 Julio 2007, 08:56 am
por Tor
Descargar archivo de FTP (wininet)
Programación C/C++
Riki_89D 3 3,934 Último mensaje 30 Enero 2011, 00:20 am
por The Swash
Dudas como Uploader [Ayuda]
Dudas Generales
BabaNK 6 3,019 Último mensaje 22 Febrero 2017, 17:57 pm
por BabaNK
Validar si un archivo subo el md5 esta repetido en otro archivo subido (DB)
PHP
Drakaris 1 3,106 Último mensaje 11 Noviembre 2018, 18:53 pm
por #!drvy
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines