Sign in to follow this  
Followers 0
Graeme

Is FTPS or FTP over SSL possible in AutoIT

10 posts in this topic

Hi,

I'm trying to download a file from a secure site that doesn't allow ftp. I've been trying to use FTPS but I can't find anything about FTPS (or FTP over SSL) except one reference that was a few years ago. So I'm wondering if things have changed. I've trawled through WinHttp and FF but can't find anything.

If anyone has some good ideas I'd love to hear from you. here is one example of what I tried, and it seemed to work at first but then there was no response at the end:(

#include <string.au3>
#include <inet.au3>
#include <guiconstants.au3>
#include <winhttp.au3>

Dim $hw_connect, $hw_open, $h_openRequest, $LocalIP, $M

$LocalIP = "https://www.example.org"

$hw_open = _WinHttpOpen()

$hw_connect = _WinHttpConnect($hw_open, $LocalIP)

$h_openRequest = _WinHttpOpenRequest($hw_connect, "GET", "programname.exe")
MsgBox(0,"",$hw_connect&@error)
$M = _WinHttpSetCredentials($h_openRequest, $WINHTTP_AUTH_TARGET_SERVER, $WINHTTP_AUTH_SCHEME_BASIC, "username", "password")
MsgBox(0,"",$M)
$M= _WinHttpSendRequest($h_openRequest)
MsgBox(0,"",$M)

$M= _WinHttpReceiveResponse($h_openRequest)
MsgBox(0,"",$M& " " &@error)

Share this post


Link to post
Share on other sites



Graeme,

Please pay attention to where you post - the "Examples" section where you started this thread is clearly marked: "This is NOT a general support forum!". I have moved the thread for you, but would ask you to be more careful in future. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I don't know if you've searched thru the forums yet, but if not, try it. Use ftps as the keyword.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Melba23 - Thanks for moving my question to the right place. Sorry that I made that error.

SoundComputerguy - Sorry I didn't specifiy that the forums were one of the places I had been also trawling through - my eyes are going square:( Any fresh ideas very welcome.

Blessings

Graeme

Share this post


Link to post
Share on other sites

WinHTTP doesn't support FTP protocol in any form.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Thanks for that trancexx. Have a good day.

Blessings

Graeme

Share this post


Link to post
Share on other sites

Don't know if it would get you where you want to go but you could try using psftp.exe (http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html).

Would need to have psftp.exe in the working directory or get it in the path of the script and you would need a separate script file for use by psftp in the working directory as well.

Script file contains the commands you want to run through psftp (example.scr):

cd /home/user

put test.txt

get test2.txt

quit

Would call it via autoit with:

Run(@ComSpec & " /c" & "psftp.exe user@hostname -pw password -b test.scr","",@SW_HIDE)

The -b test.scr is what calls the psftp script.

Share this post


Link to post
Share on other sites

Hi Wakillon,

I downloaded the libcurl.au3 etc but I can't make even the example files work? What could I be doing wrong?

Blessings

Graeme

Share this post


Link to post
Share on other sites

Hi Wakillon,

I downloaded the libcurl.au3 etc but I can't make even the example files work? What could I be doing wrong?

Blessings

Graeme

 

Try this way :

#include <libcURL.au3>

Global $bCallbackBuffer

_url2file ( 'ftps://...../filename.txt', @DesktopDir & '\filename.txt' )

Func _url2file($sURL, $sFilePath)
    ConsoleWrite ( '$sURL : ' & $sURL & @Crlf )
    Local $hcurl = _curl_easy_init()
    If $hcurl Then
        Local $tCURLSTRUCT_URL = DllStructCreate("char[" & StringLen($sURL) + 1 & "]")
        DllStructSetData($tCURLSTRUCT_URL, 1, $sURL)
        _curl_easy_setopt($hcurl, $CURLOPT_URL, DllStructGetPtr($tCURLSTRUCT_URL))
        _curl_easy_setopt($hcurl, $CURLOPT_VERBOSE, 1)
        _curl_easy_setopt($hcurl, $CURLOPT_FOLLOWLOCATION, 1)
        _curl_easy_setopt($hcurl, $CURLOPT_NOPROGRESS, 1)

        _curl_easy_setopt ( $hcurl, $CURLOPT_PORT, 990 ) ; Port 990 for the FTPS control channel, and 989 for the FTPS data channel
        _curl_easy_setopt ( $hcurl, $CURLOPT_SSL_VERIFYPEER, 0 )
        _curl_easy_setopt ( $hcurl, $CURLOPT_SSL_VERIFYHOST, 1 )
        _curl_easy_setopt ( $hcurl, $CURLOPT_USE_SSL, $CURLOPT_FTPSSLAUTH )
        _curl_easy_setopt ( $hcurl, $CURLOPT_USERPWD, 'username:password' ) ; set your username and password
        _curl_easy_setopt ( $hcurl, $CURLOPT_SSLVERSION, 3 )

        $bCallbackBuffer = ""
        Local $handle = DllCallbackRegister("_my_fwrite", "uint:cdecl", "ptr;uint;uint;ptr")
        _curl_easy_setopt($hcurl, $CURLOPT_WRITEFUNCTION, DllCallbackGetPtr($handle))
        _curl_easy_setopt($hcurl, $CURLOPT_WRITEDATA, 0)
        _curl_easy_perform($hcurl)
        DllCallbackFree($handle)
        _curl_easy_cleanup($hcurl)
        If $bCallbackBuffer Then
            ConsoleWrite("+ $bCallbackBuffer: " & $bCallbackBuffer & @CRLF)
            Local $fh = FileOpen($sFilePath, 18)
            If $fh <> -1 Then
                FileWrite($fh, $bCallbackBuffer)
                FileClose($fh)
            EndIf
        EndIf
    EndIf
EndFunc   ;==>_url2file

Func _my_fwrite($buffer, $size, $nmemb, $stream)
    Local $vData = DllStructCreate("byte[" & $size * $nmemb & "]", $buffer)
    $bCallbackBuffer &= DllStructGetData($vData, 1)
    Return $size * $nmemb
EndFunc   ;==>_my_fwrite

Not tested as i do not have access to a ftps server...

Try to adapt it to your needs  :)


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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  
Followers 0

  • Similar Content

    • Glyph
      By Glyph
      Has anyone already worked on a WSS UDF yet? I'm interested in making a project involving WSS with the ASYNC autoit library like ratchetphp / Pawl in PHP. (using reactphp)
      ASYNC is a must, and obviously WSS. the problem with some libraries i've worked with in PHP are mainly issues with handshakes like improper peer name validation (for multi level certs)
      relevant links: https://tools.ietf.org/rfc/rfc6455.txt
      https://github.com/ratchetphp/Pawl
       
      /e i should note i'm not looking for hybrid workarounds, i want to do this in autoit alone. (no javascript)
    • 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 ?
    • Xenobiologist
      By Xenobiologist
      Hi folks,
      I'm using the udf #include <FTPEx.au3> to "download" some files from our zOS (MVS) system via autoit FTP with _FTP_FileGet.
      The FileGet works, but the codepage is wrong. Special German chars like öäüß are not transfered correctly.
      Any idea how to set the codepage? Swichting between binary or ascii doesn't solve the problem.
      Using the ftp command in a cmd.exe window it works like this : quote site sbd=(IBM-273,iso8859-1)
      Thanks
      Mega
    • DCCD
      By DCCD
      Hi, how to get full error reporting if FTP failed?
       
      tried  _WinAPI_GetLastErrorMessage() func but That didn't help at all.  the information was returned by _WinAPI_GetLastErrorMessage() can't help me!
       
       
      _FTP_Open, return Success: a handle, Failure: 0 and sets the @error flag to non-zero
      _FTP_Connect,  return Success: an handle to connected session. Failure: 0 and sets the @error flag to non-zero.
      _FTP_DirCreate, return Success: 1. Failure: 0.
      _FTP_FilePut, return Success: 1. Failure: 0 and sets the @error flag to non-zero.
       
      Any help would be much appreciated