Jump to content
Sign in to follow this  

Need help getting _FTP_FilePut verbose error

Recommended Posts

I'm using _FTP_FilePut to upload a file to FTP server. I often receive an error, but if I retry (sometime it takes several retries) it will finally work. I have error checking and know the @Extended is 12003 (ERROR_INTERNET_EXTENDED_ERROR) which is described by MSDN as "An extended error was returned from the server. This is typically a string or buffer containing a verbose error message. Call InternetGetLastResponseInfo to retrieve the error text." In AutoIt, the WinAPIError.au3 only returns the @Error and @Extended code, not this verbose message. I haven't found any reference in the Includes about InternetGetLastResponseInfo. Would this be equal to _WinNet_GetLastError or _WinAPI_GetLastErrorMessage? I feel like it should be the WinNet call but I'm struggling with the call... The syntax is _WinNet_GetLastError(ByRef $iError, ByRef $sError, ByRef $sName) Parameters are:

$iError - On return, contains the most recent extended error code

$sError - On return, contains the most recent extended error code message

$sName - On return, the network provider that raised the error

I've tried calling this as: $FTPerror = _WinNet_GetLastError() but it must have ALL 3 parameters to pass syntax.I've tried giving it 3 'empty' variables ($a, $b, $c) in hopes it would populate them, but no luck. I tried telling it all three parameters are $Conn (The FTP connection handle) or $Open (The FTP Open handle) but both result in $FTPerror=0. I've added an _ArrayDisplay($aResult) to the WinNet.au3 file, and the results in the array don't make sense as I ended up with a 6 row array instead of the expected 4 row as it would appeat from WinNet.au3.

Does anyone have any suggestions on this? Possibly I should be using _WinAPI_GetLastErrorMessage instead? Or I don't understand the systax of _WinNet_GetLastError...

Here is a clip from the MSDN for InternetGetLastResponseInfo


BOOL InternetGetLastResponseInfo(

__out LPDWORD lpdwError,

__out LPTSTR lpszBuffer,

__inout LPDWORD lpdwBufferLength



lpdwError [out]

Pointer to a variable that receives an error message pertaining to the operation that failed. lpszBuffer [out]

Pointer to a buffer that receives the error text. lpdwBufferLength [in, out]

Pointer to a variable that contains the size of the lpszBuffer buffer, in TCHARs. When the function returns, this parameter contains the size of the string written to the buffer, not including the terminating zero.


The FTP protocols can return additional text information along with most errors. This extended error information can be retrieved by using the InternetGetLastResponseInfo function whenever GetLastError returns ERROR_INTERNET_EXTENDED_ERROR (occurring after an unsuccessful function call).

The buffer pointed to by lpszBuffer must be large enough to hold both the error string and a zero terminator at the end of the string. However, note that the value returned in lpdwBufferLength does not include the terminating zero.

Share this post

Link to post
Share on other sites

Wow, so many views with no replies yet! Has anyone used _WinNet_GetLastError from WinNet.au3? If so, can you inlude any example or notes explaining the syntax to get this command working? I feel that would be a good start to this problem.

Share this post

Link to post
Share on other sites

I've tried the code using _WinAPI_GetLastErrorMessage() instead of _WinNet_GetLastError in hopes that it also will contain the verbose message. So far I have not received the 12003 error but I've only tested a short while. I did remove the source file to force an error, and the verbose message worked perfectly.

11-15-2011 15:55:39 FTP upload error: -1 Extended: 2 Verbose: The system cannot find the file specified.

Hopefully it will do the same with the 12003 error I typically receive. Below is the test code I'm using. It uploads once every 5 minutes. If the upload fails, it will retry until it completes. If you have an error that is not intermittent, this script must be stopped manually or it will retry forever. To work properly, you must configure the FTP section (username and password) and create a file called FTPerrorTest.txt. Hopefully this will help others with FTP error handling and logging. Also, I'm aware this isn't highly optimized overall, but the intent here is solely for testing and properly using the verbose error logging with FTP.

#include <Date.au3>
#include <FTPEx.au3>
#include <WinNet.au3>

$AppLog = "AppLog.txt"    ; Set log file name
$username = ""
$password = ""
$ftpserver = "ftp.domain.com"
While 1
#region  ; Get current system time
$tTime = _Date_Time_GetSystemTime()
$DateTime = _Date_Time_SystemTimeToArray($tTime)
;MsgBox(1,"","Current system date/time .: " & _Date_Time_SystemTimeToDateTimeStr($tCur))
$mm = StringLeft(_Date_Time_SystemTimeToDateTimeStr($tTime),2)
$dd = StringMid(_Date_Time_SystemTimeToDateTimeStr($tTime),4,2)
$yyyy = StringMid(_Date_Time_SystemTimeToDateTimeStr($tTime),7,4)
$hour = StringMid(_Date_Time_SystemTimeToDateTimeStr($tTime),12,2)
;$min = StringMid(_Date_Time_SystemTimeToDateTimeStr($tTime),15,2)
;$sec = StringMid(_Date_Time_SystemTimeToDateTimeStr($tTime),18,2)

$error = 0
While $error = 0
Sleep (500)
$count = 0
While $count <> 5   ; Loop 5 times (5 min)
While @sec <> 0  ; Wait for xx:xx:00  (1 minute interval)
  sleep(200)  ; Sleep 2/10s and retry
$count = $count + 1
sleep(1010) ; Sleep long enough that @sec is no longer :00

Func _UploadFTP()
$Open = _FTP_Open('MyFTP Control')
If $Open = 0 Then
  $FilePutError = @Error
  $FilePutExtended = @Extended
  $FilePutVerbose = _WinAPI_GetLastErrorMessage()
  $LogFile = FileOpen($AppLog, 1) ; 1 = append
  FileWrite($LogFile, $mm & "-" & $dd & "-" & $yyyy & " " & $hour & ":" & @min & ":" & @sec & " FTP open error: " & $FilePutError & " Extended: " & $FilePutExtended & " Verbose: " & $FilePutVerbose & @CRLF)
$Conn = _FTP_Connect($Open, $ftpserver, $username, $password)
If $Conn = 0 Then
  $FilePutError = @Error
  $FilePutExtended = @Extended
  $FilePutVerbose = _WinAPI_GetLastErrorMessage()
  $LogFile = FileOpen($AppLog, 1) ; 1 = append
  FileWrite($LogFile, $mm & "-" & $dd & "-" & $yyyy & " " & $hour & ":" & @min & ":" & @sec & " FTP connect error: " & $FilePutError & " Extended: " & $FilePutExtended & " Verbose: " & $FilePutVerbose & @CRLF)
$error = _FTP_FilePut($Conn, "FTPerrorTest.txt", "FTPerrorTest.txt")
If $error = 0 Then
  $FilePutError = @Error
  $FilePutExtended = @Extended
  $FilePutVerbose = _WinAPI_GetLastErrorMessage()
  $LogFile = FileOpen($AppLog, 1) ; 1 = append
  FileWrite($LogFile, $mm & "-" & $dd & "-" & $yyyy & " " & $hour & ":" & @min & ":" & @sec & " FTP upload error: " & $FilePutError & " Extended: " & $FilePutExtended & " Verbose: " & $FilePutVerbose & @CRLF)
  $LogFile = FileOpen($AppLog, 1) ; 1 = append
  FileWrite($LogFile, $mm & "-" & $dd & "-" & $yyyy & " " & $hour & ":" & @min & ":" & @sec & " FTP upload successful" & @CRLF)
sleep (500)
$Ftpc = _FTP_Close($Open)
Edited by DrJeseuss

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...