Jump to content
Sign in to follow this  
Elia

Add File Name to FTP Debug

Recommended Posts

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By wysocki
      I have a smartphone and I use it to access my email. However, when composing an email on it I have a problem. My list of phone contacts on the phone is very different from my list of email contacts in my Thunderbird desktop app.  I use my Gmail address book to store primarily phone contacts, and I use Thunderbird for my list of email contacts. I wanted a way to get my Thunderbird contact list onto my smartphone to be able to compose emails to addresses in that list. Here's my solution.
      I wrote a script to export my Thunderbird Personal Address Book to a csv file. It then reads that file and re-writes it with html wrappers around the data to make it into a nicely formatted web page. It then uploads the htm file to my website. On my smartphone, I created a shortcut to the file's URL and whenever I click it, I get the list displayed. Each contact shows name and email address along with a COPY button that will put the address into the clipboard. Then in my email client, I can easily paste that address into it. Alternatively, clicking on the actual email link will open a new message dialog in your email client with that address already entered.
      To use the app, all you need to do is use Thunderbird and have a webserver available. You'll need to download the FTPEX.AU3 file from this website and make a few changes to some constants around line 17 for FTP login info, etc.
       
      pab2ftp.au3
    • By Dent
      The following function successfully connects to and uploads a local text file named user.dat
      I have checked the data being written to the text file when it is created locally using a MsgBox and it appears exactly how it should be written to the file. If I comment out the FileDelete and go and open the file locally it is as expected.
      However when I download the file from the FTP server and open it up the text that should be at the end of the file is missing. With each subsequent run more characters are missing.
      I added the Sleep(5000) in case the function was closing the FTP connection too quickly before the file could be fully written but it makes no difference. The user.dat file is (should be) approximately 100 bytes so it is tiny.
      Any idea why this is happening?
      Func UpdateUserData() ; Upload the modified user.dat file Local $hOpen = _FTP_Open("myftp") Local $hConn = _FTP_Connect($hOpen, "my.ftp.server", "user", "pass", 1, 0, 1, 2) If @error Then MsgBox(16, "Error", "Connection failed" & @CRLF & @CRLF & "Please contact support") _FTP_Close($hConn) _FTP_Close($hOpen) Exit EndIf _FTP_FilePut($hConn, @TempDir & "\user.dat", "user.dat") ; Upload the new user.dat file Sleep(5000) If @error <> 0 Then MsgBox(16, "Error", "Couldn't transmit data" & @CRLF & @CRLF & "Please contact support") _FTP_Close($hConn) _FTP_Close($hOpen) Exit EndIf _FTP_Close($hConn) _FTP_Close($hOpen) FileDelete(@TempDir & "\user.dat") EndFunc  
    • By Raywando
      Hello,
      This is my first post. So I’ve worked on a script for a while and I’m planning to publish it but the problem is that it connects to an FTP server at some point, and as you probably know FTP credentials are easily captured by a MITM attack or Wireshark (not sure if Wireshark does). So I thought if i can detect data capturing in the user’s network the script would stop. Any idea?.
      If there’s another workaround I’m happy to hear it. 
    • By Carm01
      Hello,
      I am attempting to pull a list of the directory structure from a public FTP where no username or password is required i.e:
      ftp://ftp.adobe.com/pub/adobe/
      Now I have looked all over the place and have failed find anything to accomplish, and if I found some, and the documentation is rather bleak for example;
      it does show something I am looking for, but there is no ftp.au3, and the usage and examples of what i want to do seems to elude me on this and it may not even apply to what I am trying to accomplish?
      I want to avoid using things with Internet explorer , and I have done some google searches. However nothing seems to help
      the documentation surrounding : _FTP_DirGetCurrent  references _FTP_Connect , and then references _FTP_Open , and regardless what I try I cannot get it to pull a list of directorys of files as a list.
       
      Any help is appreciated
       
       
       
    • By Jemboy
      Hi,
      Ones(some times twice) a month I get an e-mail with zip file, which has price updates from a supplier.
      I have to upload the file to an FTP to get it processed.
      When uploading the file, it will get "timestamped" with the time and date at which time the file was uploaded.
      Normally this is fine, because I mostly upload the file the same day.
      Sometimes it may take 1 or 2 days before I can upload the file.
      For historical purpose, I would like to have the file timestamped with the original date.
      I have tried using:  _FTP_Command ( $hFTPSession, "MFCT YYYYMMDDHHMMSS path") 
      however this command does not work or change the timestamp as I expected.
      Does anyone now a way how I can change the timestamp of a FTP-file?
×
×
  • Create New...