Elia

Add File Name to FTP Debug

1 post in this topic

Hi All,

I need some help, I am writing a script that FTPs some files and then outputs the results, but I am unable to figure out how to output the file name on line 58. Here is the code (modified to exclude personal information):

 

  1. #include <FTPEx.au3>
  2. #include <MsgBoxConstants.au3>
  3. #include <WinAPIFiles.au3>
  4. #include <Inet.au3>
  5. #include <Debug.au3>
  6. #include <File.au3>
  7. #include <Array.au3>
  8. Local $Server = 'ftp.com'
  9. Local $Username = 'user'
  10. Local $Password = 'password'
  11. Local $LocalFolder = 'C:\Folder'
  12. Local $RemoteFolder = '/users/user1'
  13. Local $SMTPServer = "Exchange.domain.com"
  14. Local $FromName = "FTP"
  15. Local $FromAddress = "email@address.com"
  16. Local $ToAddress = " email@address.com "
  17. Local $Subject = "FTP Transfer Failed, please check server"
  18. Local $Subject1 = "FTP Connection Failed, please check server"
  19. Local $Body[2]
  20. $Body[0] = "Line 1"
  21. $Body[1] = "Line 2"
  22. Local $Body1[2]
  23. $Body1[0] = "Line 1"
  24. $Body1[1] = "Line 2"
  25. $LogFolder = "\\COMP\LOGS"
  26.  
  27. _DebugSetup ("Debug", True)
  28.  
  29. FileMove ("\\COMP\Test\*.txt", "\\COMP\FTP")
  30.  
  31. Local $FolderContents = _FileListToArray("\\COMP\FTP")
  32. Local $LogFile = "\FilesToSend_" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & ".log"
  33. _FileCreate($LogFolder & $LogFile)
  34. _FileWriteFromArray($LogFolder & $LogFile, $FolderContents)
  35.  
  36. If FileExists ( "\\COMP\FTP" ) Then
  37.     Local $Open = _FTP_Open('FTP')
  38.     Local $CallBack = _FTP_SetStatusCallback($Open, 'FTPStatusCallbackHandler')
  39.     Local $Connect = _FTP_Connect($Open, $Server, $Username, $Password, 0, $INTERNET_DEFAULT_FTP_PORT, $INTERNET_SERVICE_FTP, 0, $CallBack)
  40.         If $Connect <> 0 Then
  41.             Local $Transfer = _FTP_DirPutContents($Connect, $LocalFolder, $RemoteFolder, 0)
  42.             _FTP_Close($Connect)
  43.             _FTP_Close($Open)
  44.                 Else
  45.             _INetSmtpMail($SMTPServer, $FromName, $FromAddress, $ToAddress, $Subject1, $Body, "EHLO" & @ComputerName, -1)
  46.         EndIf
  47.             If $Transfer = 1 Then
  48.                 FileMove ( "\\COMP\FTP\*.txt", "\\COMP\Test\SENT")
  49.                 Else
  50.                 _INetSmtpMail($SMTPServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body1, "EHLO" & @ComputerName, -1)
  51.             EndIf
  52. EndIf
  53. Func FTPStatusCallbackHandler($hInternet, $iContext, $iInternetStatus, $pStatusInformation, $iStatusInformationLength)
  54.                     #forceref $hInternet, $iContext
  55.                     If $iInternetStatus = $INTERNET_STATUS_REQUEST_SENT or $iInternetStatus = $INTERNET_STATUS_RESPONSE_RECEIVED Then
  56.                         Local $iBytesRead
  57.                         Local $tStatus = DllStructCreate('dword')
  58.                         _WinAPI_ReadProcessMemory(_WinAPI_GetCurrentProcess(), $pStatusInformation, $tStatus, $iStatusInformationLength, $iBytesRead)
  59.                         _DebugOut(_FTP_DecodeInternetStatus($iInternetStatus) & ' | Size = ' & DllStructGetData($tStatus, 1) & ' Bytes    Bytes read = ' & $iBytesRead)
  60.                     Else
  61.                         _DebugOut(_FTP_DecodeInternetStatus($iInternetStatus))
  62.                     EndIf
  63.                     EndFunc

I would like the output on line 58 to include a file name, at the moment it only displays the size of the file and Bytes read. Here is what is currently outputted:

Handle created
Resolving name ...
Name resolved
Connecting to server ...
Connected to server
Receiving response ...
Response received | Size = 58 Bytes    Bytes read = 4
Sending request ...
Request sent | Size = 13 Bytes    Bytes read = 4
Receiving response ...
Response received | Size = 20 Bytes    Bytes read = 4
Sending request ...
Request sent | Size = 19 Bytes    Bytes read = 4
Receiving response ...
Response received | Size = 20 Bytes    Bytes read = 4
Handle created
Handle created
Handle created
Handle created
Handle created
Closing connection ...
Connection closed
Handle closing ...

Any help would be greatly appreciated! :)

Thanks.

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

  • Similar Content

    • Sigmac
      By Sigmac
      I have used this code for a long time, but for a week or 2 it stopped working?
      Connection is ok, the put create the file on server if I delete it on the FTP server, but the file is empty and after 30 secondees the function return 0
      I have tested on 2 machines, Filezilla FTP client have no issue to the server.
      Firewall is disabled under test.
        If $writeFTP = True Then
            $Open=_FTPOpen('MyFTP Control')
            $Conn=_FTPConnect($Open, $destinationServer, $destinationUsername, $destinationPass)
       MsgBox(0,"start","start")
            $Ftpp=_FtpPutFile($Conn, $filePath&$name&".json", "httpdocs/p_calender/" & $name & ".json")
      MsgBox(0,"return","return"&$Ftpp)
      Exit
            $Ftpc=_FTPClose($Open)
           EndIf
       
      From the Lib:
      Func _FTPPutFile($l_FTPSession, $s_LocalFile, $s_RemoteFile, $l_Flags = 0, $l_Context = 0)
          Local $ai_FTPPutFile = DllCall('wininet.dll', 'int', 'FtpPutFile', 'long', $l_FTPSession, 'str', $s_LocalFile, 'str', $s_RemoteFile, 'long', $l_Flags, 'long', $l_Context)
          If @error OR $ai_FTPPutFile[0] = 0 Then
              SetError(-1)
              Return 0
          EndIf
          Return $ai_FTPPutFile[0]
      EndFunc ;==> _FTPPutFile()
       
    • mLipok
      By mLipok
      As for now I was using such kind of snippet:
      Local $aFTP_FileList = _FTP_ListToArray($hFTPSession, 2) For $iFTPFileSize_idx = 1 To $aFTP_FileList[0] ConsoleWrite('Pobieram informacje o pliku:' & $aFTP_FileList[$iFTPFileSize_idx] ) $iWielkoscPliku = _FTP_FileGetSize($hFTPSession, $aFTP_FileList[$iFTPFileSize_idx]) ConsoleWrite($iFTPFileSize_idx & ' : ' & $aFTP_FileList[$iFTPFileSize_idx] & ' rozmiar=' & $iWielkoscPliku) Sleep(200) Next  
      But from some time my clients start buying cheap WD MyCloud NAS, and my problems starts.
      On all others NAS there is no problem (Seagate BlackArmour, QNAP, SYNOLOGY .... ).

      When on list there is for example 20 files then first two of them are very fast checked and reported they FileSize.
      After 2 files there is about 20 sec stop....... and next two files are checked with no errors but FileSize == 0 
      again there is about 20 sec stop....... and next two files are checked with no errors but FileSize == 0 
      again there is about 20 sec stop....... and next two files are checked with no errors but FileSize == 0 
      again there is about 20 sec stop....... and next two files are checked with no errors but FileSize == 0 
      again there is about 20 sec stop....... and next two files are checked with no errors but FileSize == 0 
      .......
       
      In time when I process investigation I checked how :  _FTP_ListToArray2D and _FTP_ListToArrayEx works and I was shocked that they works super fast.
       
      Here are the questions:
      Q1: Why does the problem occur only on WD MyCloud NAS?
      Q2: What is the significant difference that makes using _FTP_ListToArray2D and _FTP_ListToArrayEx to retrieve file sizes is still fast?
      Q3: Why _FTP_FileGetSize() not reporting @errors but returned FileSize = 0 
       
      Regards,
      mLipok
       
    • mLipok
      By mLipok
      In documentation for:
       
      #include <FTPEx.au3> _FTP_Connect ( $hInternetSession, $sServerName, $sUsername, $sPassword [, $iPassive = 0 [, $iServerPort = 0 [, $iService = $INTERNET_SERVICE_FTP [, $iFlags = 0 [, $fuContext = 0]]]]] ) There are two parameters for Passive:
       
      My question is: 

      What is a difference beetwen  using :
      $iPassive = 1
      and
      $iFlags =     $INTERNET_FLAG_PASSIVE
      Regards,
      mLipok
       
    • Xandy
      By Xandy
      Screenshot program that can upload/FTP to website/storage with hotkey.
      Features GUI to display programmable keys.

      Set the hotkeys with this function to use, and display hotkeys.
      ; hotkey_set() Parameters: ; ----------------------------------------------------------- ; $aHotkey -                The array hotkeys are stored in. This function sets the values of this array[hotkey_id][$hotkey_data] ; $dHotkey_id -             The enum for this hotkey index ; $sHotkey_description -     The label displayed to the user to represent function of hotkey ; $sHotkey_name -            The hotkey it'self.  Whatever name string you want to give the key ; $dHotkey_key -             The _IsPressed keycode ;    Keycodes AT: https://www.autoitscript.com/autoit3/docs/libfunctions/_IsPressed.htm ; $dHotkey_shift -             Shift flag 0 or 1 Default off ; $dHotkey_ctrl -             Ctrl flag 0 or 1 Default off ; $dHotkey_alt -             Alt flag 0 or 1 Default off Func hotkey_set(ByRef $aHotkey, $dHotkey_id, $sHotkey_description, $sHotkey_name, $dHotkey_key, $dHotkey_shift = 0, $dHotkey_ctrl = 0, $dHotkey_alt = 0)     $aHotkey[$dHotkey_id][$eHotkey_data_key_description] = $sHotkey_description     $aHotkey[$dHotkey_id][$eHotkey_data_key_name] = $sHotkey_name     $aHotkey[$dHotkey_id][$eHotkey_data_key] = $dHotkey_key     $aHotkey[$dHotkey_id][$eHotkey_data_shift] = $dHotkey_shift     $aHotkey[$dHotkey_id][$eHotkey_data_ctrl] = $dHotkey_ctrl     $aHotkey[$dHotkey_id][$eHotkey_data_alt] = $dHotkey_alt EndFunc   ;==>hotkey_set ; You can set your hotkeys here ; Please visit the hotkey_set() function for parameter information hotkey_set($aHotkey, $eHotkey_screenshot_ftp, "Selected Window to FTP", "F12", "7B", 0, 1, 0); F12 hotkey_set($aHotkey, $eHotkey_screenshot_disk, "Selected Window to Disk", "S", "53", 1, 1, 1); S hotkey_set($aHotkey, $eHotkey_clipboard_send, "Send Clipboard keystrokes", "F10", "79", 1, 1, 1); F10  
      Configure settings dialog:

      Screenshot Filename and Screenshot Counter, are used to create simple unique filenames that can cycle. Copy URL to clipboard option. - For linking your screenshots. The screenshot file type is for local copy only. App always uses .JPG for FTP right now, but I could add FTP screenshot file type specification.  
      Any suggestions?  Did I break anything, what did I miss?
      Package uses TTS.au3 by Beege: 
       
      FTP_Screen.zip
      File includes:
         - FTP_Screen.au3
         - FTPScreen.ico
         - TTS.au3 - by Beege
    • drorshem
      By drorshem
      Hi,
      I'm looking to create a script which will download all *.txt files from a remote FTP server.
      Once downloaded, delete all *.txt files.
       
      Can this be achieved using AutoIt ?