|
71
|
Programación / Programación C/C++ / 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? #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; }
|
|
|
72
|
Programación / Programación C/C++ / Aver si podeis ayudar con este codigo: Wininet ftp
|
en: 5 Septiembre 2013, 02:58 am
|
Me vendria bien una mano.... No lee el archivo con InternetReadFile.
void main() {
HINTERNET hSession = InternetOpen(L"WinInet Progress Sample", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_PASSIVE);
HINTERNET hConnection = InternetConnect(hSession,L"LESCOMEDIENSPLUS.BESABA.COM", // Server 21, L"u115059645", // Username L"toni12883", // Password INTERNET_SERVICE_FTP, 1, // Synchronous NULL); // No Context
// Download a file HINTERNET hTransfer = NULL;
HANDLE hFileDownload = NULL; TCHAR tchName[MAX_PATH] = TEXT("public_html\\test.sql");
// Open the transfer hTransfer = FtpOpenFile(hConnection, tchName, GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
if (hTransfer == INVALID_HANDLE_VALUE) { printf("Unable to open remote File"); system("pause"); return; }
// Ok, the file transfer is active. Create a new file to write to hFileDownload = CreateFile(TEXT("c:\\index.txt"), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFileDownload == INVALID_HANDLE_VALUE) { printf("Unable to open Destination File"); return; }
// Looks like everything's ok, so use InternetReadFile to download // the file char data_from_url[4096]; DWORD NumberOfBytesRead = 0; while(InternetReadFile(hTransfer, data_from_url, 4096, &NumberOfBytesRead) && NumberOfBytesRead ) { cout << data_from_url; }
system("pause");
CloseHandle(hFileDownload); InternetCloseHandle(hTransfer); }
|
|
|
75
|
Programación / Desarrollo Web / Re: Crear efecto radiobutton con checkboxes en js.
|
en: 18 Julio 2013, 22:20 pm
|
Ya esta: <script type="application/javascript"> function selectOnlyOne(current_clicked) { //alert(current_clicked); var a = document.getElementById(current_clicked).value; alert(a); if(a=='ac-1'){ document.getElementById('ac-3').checked=false; }else if(a=='ac-3'){ document.getElementById('ac-1').checked=false; } }
</script>
|
|
|
79
|
Programación / Desarrollo Web / Abrir pagina dentro de div. Ayuda
|
en: 11 Julio 2013, 12:57 pm
|
Estoy intentando abrir una pagina dentro de un div... Carga la pagina pero pierde la funcion de menu acordeon... ocea, que el menu no se despliega. Este es el codigo de la pagina que quiero abrir [avisos1.php]
<link rel="stylesheet" href="acordeonmenu/css/reset.css" type="text/css" charset="utf-8"> <link rel="stylesheet" href="acordeonmenu/css/core.css" type="text/css" charset="utf-8"> <link rel="stylesheet" href="acordeonmenu/css/accordion.core.css" type="text/css" charset="utf-8"> <link href="acordeonmenu/acordeon.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="acordeonmenu/js/jquery-1.4.2.min.js" charset="utf-8"></script> <script type="text/javascript" src="acordeonmenu/js/jquery.accordion.2.0.js" charset="utf-8"></script> <link href="STYLE/horizontalmenu.css" rel="stylesheet" type="text/css" />
<ul id="example2" class="accordion"> <li> <h3 >Avisos</h3> <div id="asdf" class="panel loading"> <p> <table width="100%" border="1" class="tablaavisos" id="as"> <tr> <td width="26%" height="20">Nombre</td> <td width="37%">Apellido</td> <td width="18%">D.N.I.</td> <td width="19%">Dias</td> </tr> </table> </p> </div> </li> </ul>
<script type="text/javascript"> $('#example2').accordion({ canToggle: true }); $(".loading").removeClass("loading"); </script>
Y este es el codigo de la pagina que se encarga de abrir avisos1.php mediante ajax [index.php] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Documento sin título</title>
<link rel="stylesheet" href="acordeonmenu/css/reset.css" type="text/css" charset="utf-8"> <link rel="stylesheet" href="acordeonmenu/css/core.css" type="text/css" charset="utf-8"> <link rel="stylesheet" href="acordeonmenu/css/accordion.core.css" type="text/css" charset="utf-8"> <link href="acordeonmenu/acordeon.css" rel="stylesheet" type="text/css"> <link href="STYLE/tablaavisos.css" rel="stylesheet" type="text/css" /> <link href="STYLE/botonavisos.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="acordeonmenu/js/jquery-1.4.2.min.js" charset="utf-8"></script> <script type="text/javascript" src="acordeonmenu/js/jquery.accordion.2.0.js" charset="utf-8"></script> <link href="STYLE/horizontalmenu.css" rel="stylesheet" type="text/css" /> </head>
<body>
<a href="#" onClick="getID(this)" title="Avisos"><span>Avisos</span></a> <div id="contenido"></div> </body> </html>
<script type="text/javascript"> function getID(theLink){
enviar(theLink.id);
}
function enviar(idform){ // Comprobamos que está disponible AJAX if(window.XMLHttpRequest) { ajax = new XMLHttpRequest() } // La respuesta aparecerá en una alerta ajax.onreadystatechange=function(){ if(ajax.readyState == 4) { if(ajax.status == 200) { //print(ajax.responseText) //an.style.display='none'; document.getElementById("contenido").innerHTML=ajax.responseText;
} } } // Pedimos el archivo "prueba.php" ajax.open("POST","avisos1.php",true) ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded") ajax.send(null) } </script>
|
|
|
80
|
Programación / Desarrollo Web / Ayuda con este codigo. Cargar pagina en div mediante ajax.
|
en: 28 Junio 2013, 16:01 pm
|
El siguiente codigo muestra la pagina prueba.php en el div asdf. pero al momento de mostrar la pagina prueba.php, la muestra pero con la misma desaparece. echo '<form name="form1" id="form1" method="post" action="#"> <table width="100%" height="81" border="1"> <tr> <td width="12%">Buscar DNI</td> <td width="88%"><input type="text" name="dni" id="dni"></td> </tr> <tr> <td height="40"> </td> <td><input type="submit" name="BUSCAR" id="ana" onclick="javascript:getIDA(this)" value="BUSCAR";></td> </tr> </table> </form>'; ?> <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<div id="asdf"></div>
<script type="text/javascript"> function getIDA(theLink){
alert("entro getida"); enviarA(theLink.id);
}
function enviarA(idform){ alert(idform); // Comprobamos que está disponible AJAX if(window.XMLHttpRequest) { ajax = new XMLHttpRequest() } // La respuesta aparecerá en una alerta ajax.onreadystatechange=function(){ if(ajax.readyState == 4) { if(ajax.status == 200) { //print(ajax.responseText) //an.style.display='none'; document.getElementById("asdf").innerHTML=ajax.responseText;
} } } // Pedimos el archivo "prueba.php" ajax.open("POST","prueba.php",true) ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded") ajax.send("&MM_insert=" + "renovar" + "&dni=" + idform ) } </script>
SOLUCIONADOˇˇ. Solo tenia que eliminar los formularios
|
|
|
|
|
|
|