Jump to content
Sign in to follow this  
FreeRider

InterNetWriteFile Structure ?

Recommended Posts

*** PROBLEM FIXED *****

I found a bypass to avoid the Error returned by the "FtpOpenFile" dll function when trying to open a file with the "$GENERIC_WRITE" parameter

Now Both FtpFileRead and FtpFileWrite functions works and I will post a new version of the FTPV4.AU3 file which will include these functions.

Postin Location will be : http://www.autoitscript.com/forum/index.ph...st&id=19302

*** End of Block ********

*** Update Problem desc *****

Problem comes from the FtpOpenFile function which does not work with the GENERIC_WRITE access parameter

Using GENERIC_READ do not produce any error... but do not allow to write into the file

IF SOMEONE COULD HELP... I WOULD APPRECIATE...

Thks

***************************

Hi all,

I'm looking for a function using the "InterNetWriteFile" function inlcuded in the Wininet.dll. i found one sample script in the forum but the autor says in the script

that the function do not work. I made a personal script but this does not work (Pointer problem I think).

Here is the code of the function (base on the _FtpReadFile function which works fine)

Thanks for your help...

CODE

Func _FTPWriteFile($l_FTPSession,$SourceFile,$RemoteFile,$AccessType)

Local $s_FileRead = "",$BytesWritten = 0,$dwNumberOfBytesToWrite,$lpdwNumberOfBytesWritten

Local $dwNumberOfBytesToWrite = FileGetSize($SourceFile)

Local $ai_FTPGetSizeHandle = DllCall('wininet.dll', 'int', 'FtpOpenFile', 'long', $l_FTPSession, 'str', $RemoteFile, 'long', $AccessType, 'long', 0x04000002, 'long', 0)

Local $LocFileHndl=FileOpen($SourceFile,16)

Local $DataToWrite=FileRead($LocFileHndl)

MsgBox(0,"DATA TO WRITE",$DataToWrite)

$lpBuffer = DllStructCreate("byte[" & StringTrimLeft($DataToWrite,2) & "]")

$lpdwNumberOfBytesWritten = DllStructCreate("long")

Local $ai_FTPReadFile = DllCall('wininet.dll', 'int', 'InternetWriteFile', _

'hwnd', $ai_FTPGetSizeHandle[0], _ ; HINTERNET hFile

'ptr', DllStructGetPtr($lpBuffer), _ ;LPVOID lpBuffer

'dword', $dwNumberOfBytesToWrite, _ ;DWORD dwNumberOfBytesToWrite

'ptr',DllStructGetPtr($lpdwNumberOfBytesWritten)) ;LPDWORD lpdwNumberOfBytesWritten

$BytesWritten = DllStructGetData($lpdwNumberOfBytesWritten,1)

If @error OR $ai_FTPReadFile[0] == 0 Then

$lpBuffer = 0

$lpdwNumberOfBytesWritten = 0

If $BytesWritten == 0 Then

SetError(-1) ;end-of-file error

Else

SetError(1) ;general error

EndIf

Return 0

EndIf

$s_FileRead = DllStructGetData($lpBuffer,1);index is omitted so the entire array is written into $s_FileRead as a BinaryString

$lpBuffer = 0

$lpdwNumberOfBytesWritten = 0

If $BytesWritten = 1 Then

Return _HexToString ( StringTrimLeft(Chr($s_FileRead),2)) ;without this a 1 byte read will return a decimal value of the 8 bits read

Else

Return _HexToString ( StringTrimLeft($s_FileRead,2)) ;return as binarystring (character string where all 0-255 ASCII values are allowed)

EndIf

EndFunc

Edited by Christophe Savard

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...