Jump to content

FTP_Ex.au3 - FTPWriteFile() missing ?


 Share

Recommended Posts

Im using FTP_Ex.au3 and have found that i cant see how to "write" or more correctly "append" to a remote text file on the server ?

the UDF talks about writing to a remote file but i just dont see how. Below is the remarks for _FTPopenFile() from FTP_Ex.au3 and it says $dwAccess can be set to either read or write & also says "Return Value(s): On Success - Returns the handle to ftp file for read/write with _FTPReadFile()". does that mean you use _FTPReadFile() to write (surly not) but when i look for the expected _FTPWriteFile() or _FTPAppendFile() i cant find it (dont exist in my copy of FTP_Ex.au3) ?

; Function Name: _FTPOpenFile()

; Description: Initiates access to a remote file on an FTP server for reading or writing. Use _FTPCloseFile()

; to close the ftp file.

; Parameter(s): $hConnect - The long from _FTPConnect()

; $lpszFileName - String of the ftp file to open

; $dwAccess - GENERIC_READ or GENERIC_WRITE (Default is GENERIC_READ)

; $dwFlags - Settings for the transfer see notes below (Default is 2 for FTP_TRANSFER_TYPE_BINARY)

; $dwContext - (Not Used) See notes below

; Requirement(s): DllCall, wininet.dll

; Return Value(s): On Success - Returns the handle to ftp file for read/write with _FTPReadFile()

; On Failure - 0 and Sets @error = -1

I could just read the text file and append it locally then "put" it back up, but it does say after opening a remote file it can be read or written to so i was wondering how?

Cheers all.

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Link to comment
Share on other sites

I did find this http://www.autoitscript.com/forum/index.php?showtopic=69182&st=0&p=507760&hl=write%20to%20ftp%20file&fromsearch=1&#entry507760 although it did give me a good chuckle it didn't get an answer to the question ;)

Also iv had second thoughts about appending the text file locally and then putting it back up because if this file starts getting large its going to be a bad method.

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Link to comment
Share on other sites

bump,

Iv been searching for a couple of hours this morning but cant find an answer.

#include <FTP_Ex.au3>
$l_InternetSession = _FTPOpen("ftp_test")
$s_ServerName = "Server"
$s_Username = "User"
$s_Password = "PW"
$FTP_connect = _FTPConnect($l_InternetSession, $s_ServerName, $s_Username, $s_Password)
$open = _FTPOpenFile($FTP_connect, "JD/test.txt", "GENERIC_WRITE")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $open = ' & $open & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
If $open = 0 Then
    _FTPputfile($FTP_connect, "C:\test.txt", "JD/test.txt")
    $open = _FTPOpenFile($FTP_connect, "JD/test.txt", "GENERIC_WRITE")
EndIf
_FTPappendfile($open, "Text to be added to the remote text file")
_FTPClosefile($FTP_connect)
_FTPclose($l_InternetSession)
_FTPUnInit()

What am i missing ? how do i write or append to a remote text file ?

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Link to comment
Share on other sites

Im using FTP_Ex.au3 and have found that i cant see how to "write" or more correctly "append" to a remote text file on the server ?

the UDF talks about writing to a remote file but i just dont see how. Below is the remarks for _FTPopenFile() from FTP_Ex.au3 and it says $dwAccess can be set to either read or write & also says "Return Value(s): On Success - Returns the handle to ftp file for read/write with _FTPReadFile()". does that mean you use _FTPReadFile() to write (surly not) but when i look for the expected _FTPWriteFile() or _FTPAppendFile() i cant find it (dont exist in my copy of FTP_Ex.au3) ?

; Function Name: _FTPOpenFile()

; Description: Initiates access to a remote file on an FTP server for reading or writing. Use _FTPCloseFile()

; to close the ftp file.

; Parameter(s): $hConnect - The long from _FTPConnect()

; $lpszFileName - String of the ftp file to open

; $dwAccess - GENERIC_READ or GENERIC_WRITE (Default is GENERIC_READ)

; $dwFlags - Settings for the transfer see notes below (Default is 2 for FTP_TRANSFER_TYPE_BINARY)

; $dwContext - (Not Used) See notes below

; Requirement(s): DllCall, wininet.dll

; Return Value(s): On Success - Returns the handle to ftp file for read/write with _FTPReadFile()

; On Failure - 0 and Sets @error = -1

I could just read the text file and append it locally then "put" it back up, but it does say after opening a remote file it can be read or written to so i was wondering how?

Cheers all.

File access. This parameter can be GENERIC_READ or GENERIC_WRITE, but not both.

http://msdn.microsoft.com/en-us/library/aa384166(v=VS.85).aspx

#Include <FTPEx.au3>
#include <Math.au3>
#include <WinAPI.au3>
;Const $GENERIC_READ = 80000000 
;Const $GENERIC_WRITE = 40000000
Dim $nBytes 
$FileName = @ScriptDir & "\File.txt"
$FileSize = FileGetSize($FileName)
$tBuffer = DllStructCreate("byte[" & $FileSize & "]")
$hFile = _WinAPI_CreateFile($FileName, 2, 2)
_WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer),$FileSize,$nBytes)
_WinAPI_CloseHandle($hFile)
$Open = _FTP_Open('MyFTP Control')
$Conn = _FTP_Connect($Open,"FTP Server/Host","FTP Login/Username" ,"FTP Password",1)
if $Conn Then
$BOOL = _FTP_DirCreate($Conn,"Dir")
$FileOpen =  _FTP_FileOpen($Conn,"Dir/File.txt",$GENERIC_WRITE,2,0)
;File access. This parameter can be GENERIC_READ or GENERIC_WRITE, but not both.
;http://msdn.microsoft.com/en-us/library/aa384166(v=VS.85).aspx
if $FileOpen Then
Dim $MovePos = 0 ,$lpdwNumberOfBytesWritten
While 1
$dwNumberOfBytesToWrite = _Min (101, $FileSize - $MovePos)
if $MovePos = $FileSize Then ExitLoop
$OutPtr = DllStructGetPtr($tBuffer) + $MovePos
$RT = DllCall($__ghWinInet_FTP,'int','InternetWriteFile','handle',$FileOpen,'ptr',$OutPtr,'dword',$dwNumberOfBytesToWrite,'dword*',0)
if Not @error Then
$lpdwNumberOfBytesWritten = $RT[4]
$MovePos += $lpdwNumberOfBytesWritten
EndIf
WEnd
MsgBox(0,$MovePos,$FileSize)
DllCall($__ghWinInet_FTP, 'int', 'InternetCloseHandle', 'handle',$FileOpen)
EndIf
DllCall($__ghWinInet_FTP, 'int', 'InternetCloseHandle', 'handle',$Open)
EndIf

_FTP_Connect($l_InternetSession, $s_ServerName, $s_Username, $s_Password [, $i_Passive = 0 [, $i_ServerPort = 0 [, $l_Service = 1 [, $l_Flags = 0 [, $l_Context = 0]]]]])

$i_Passive = 1

Edited by wolf9228

صرح السماء كان هنا

 

Link to comment
Share on other sites

Many thx, i shall check it out and if i can get it to work i'll prob make a func out of it and then add that func as _FTP_WriteFile(***...) to the FTP_Ex.au3 udf.

Wonder why the creator of FTP_Ex.au3 never scripted this function, he did _FTPReadFile() but not _FTPWriteFile()

anyhow thx for the script-et

Cheers wolf9228

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...