Sign in to follow this  
Followers 0
JohnMC

FTP UDF (Updated 1-10)

46 posts in this topic

#1 ·  Posted (edited)

The FTP UDF Sticky thread had been mostly dead and consists of outdated code, i hope this can be useful to someone.

(Update) My focus with updates to come for this UDF will be around simplicity, because with the WinINet UDF complex and more reliable functions are possible but are just that: "Complex"

Here is a list of available functions:

_FTPOpen

_FTPConnect

_FTPPutFile

_FTPPutFolderContents

_FTPGetFile

_FTPGetFoldercontents (Known to cause errors when ran uncompiled or without admin privs?)

_FTPDelFile

_FTPRenameFile

_FTPMakeDir (Returns 0 / error if directory already exists)

_FTPDelDir

_FTPGetFileSize

_FTPGetCurrentDir

_FTPSetCurrentDir

_FTPFindFileFirst

_FTPFindFileNext

_FTPFindFileClose

_FTPClose

The largest differences from this UDF and the Original FTP UDF:

-You no longer need to use DLLOpen() - Its called from _FTPOpen

-All Functions now use the handle from _FTPOpen, and NOT _FTPConnect.

20090110

*Added: In _FTPConnect() Setting $l_Flags to 1 will enable Passive Mode

*Added: In _FTPGetFile() Setting $l_Flags will change transfer type 1=BIN 2=ASC

*Fixed: _FTPGetFileSize()

*Fixed: _FTPGetCurrentDir()

*Fixed: Code improvements

*Documentation: Example file updated

20080910

*Fixed: Code improvements

*Added: _FTPGetFoldercontents, it doesnt use true recursion but it will download subdirectories and has a switch to specify not to

20080818

*Fixed: Minor code improvements and and removed some depreciated code

*Documentation: Added _FTPFileFindClose to the example along with some comments

20080816

*Changed: _FTPOpen returns an array containing all handles, if a function that uses handles like _FTPFileFindFirst is called, it adds to the array instead of returning the handle

http://teammc.cc/aut_ftp/

Edited by JohnMC

Share this post


Link to post
Share on other sites



Thanks - I was beginning to think this UDF was dying by degrees.

Seems that the variable $handles on line 322 should read $s_handles, no?

With that changed (corrected?) this version seem to work fine for me, although only with a subset of the functions.

Chris

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks - I was beginning to think this UDF was dying by degrees.

Seems that the variable $handles on line 322 should read $s_handles, no?

With that changed (corrected?) this version seem to work fine for me, although only with a subset of the functions.

Chris

yes your right, i was a bit to excited just to post this i guess, ill update tonight when im done adding these additional functions.

Edited by JohnMC

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I don't mean to hijack the thread, but since the topic of "revitalizing" the FTP.au3 UDFs has come up... FWIW, I was hoping we could take the FTP UDFs in a slightly different, more generalized direction by wrapping most of the WinINet functions in AutoIt, of which the FTP functions are actually a subset (so the current functionality for FTP is present, but in addition to functions for HTTP and GOPHER+). It makes for a much more powerful base from which users can build FTP/HTTP-enabled scripts, as it'd have a wider scope and while maintaining a relatively coherent/consistent API across the protocols.

You'll find the functions here. Unfortunately, there's been very little feedback in that thread after almost 2 weeks :\

Edited by -Ultima-

[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

Share this post


Link to post
Share on other sites

I don't mean to hijack the thread, but since the topic of "revitalizing" the FTP.au3 UDFs has come up... FWIW, I was hoping we could take the FTP UDFs in a slightly different, more generalized direction by wrapping most of the WinINet functions in AutoIt, of which the FTP functions are actually a subset (so the current functionality for FTP is present, but in addition to functions for HTTP and GOPHER+). It makes for a much more powerful base from which users can build FTP/HTTP-enabled scripts, as it'd have a wider scope and while maintaining a relatively coherent/consistent API across the protocols.

You'll find the functions here. Unfortunately, there's been very little feedback in that thread after almost 2 weeks :\

sounds great, but i dont feel i would be able to do that anytime soon, its kinda beyond me, i spent alot of time on msdn looking at those very commands and your right to say they should be wraped, but with ftp logins and everything i would have to really sit down and think... in the meantime i updated the FTP UDF it kinda strays away from the original method of the handles so i hope that its still usefull for whatever people might need, but i feel it really makes the the entire thing alot easier...

Share this post


Link to post
Share on other sites

Hello! very new to this forum! First post! I really need a function to download the folder contents on an ftp server. I came across a function which apparently does so called _ftpgetfoldercontents but it doesn't seem to work. could anyone point me in the direction of one that does work please?

I would be ultimately great full!!!

Thanks in advance!!!

Share this post


Link to post
Share on other sites

Hello! very new to this forum! First post! I really need a function to download the folder contents on an ftp server. I came across a function which apparently does so called _ftpgetfoldercontents but it doesn't seem to work. could anyone point me in the direction of one that does work please?

I would be ultimately great full!!!

Thanks in advance!!!

This is not the right place for your question.

Create a new thread in the supportforum with your issue and post the code you use.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Hello! very new to this forum! First post! I really need a function to download the folder contents on an ftp server. I came across a function which apparently does so called _ftpgetfoldercontents but it doesn't seem to work. could anyone point me in the direction of one that does work please?

I would be ultimately great full!!!

Thanks in advance!!!

post a link to the code you found, ill review it and see if it would be a good addition to this UDF

Share this post


Link to post
Share on other sites

Seems like you made the changes in a rush again ;)

I think the parameter in Func _FTPFileFindClose($h_Handle) (line 464) should be $l_FTPSession, no?

With that change, my code compiles OK.

I think you've also got a couple of other references to $h_Handle in the comments (see lines 369 and 456) which probably need to change.

Chris

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Earlier posted an apparent problem. Turns out the problem was with my code - sorry.

However, I think the parameter problem remains

Chris

Edited by ChrisJakarta

Share this post


Link to post
Share on other sites

post a link to the code you found, ill review it and see if it would be a good addition to this UDF

Thanks for the response. Here is the link to the _FTPGetFoldercontents function i found.

_FTPGetFoldercontents Link

Thanks again.

Share this post


Link to post
Share on other sites

I occasionally have problems connecting to the server. Is there any way to add a time-out to the _FTPConnect() function, to stop the program going into never-never land? Grateful for any ideas...

Chris

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Setting the timeout is possible for WinInet InternetConnect handles by using wininet.dll's InternetSetOption in conjunction with...

INTERNET_OPTION_CONNECT_TIMEOUT - for connection requests

INTERNET_OPTION_RECEIVE_TIMEOUT - for receiving request responses

INTERNET_OPTION_SEND_TIMEOUT - for sending requests

and passing a DWORD struct containing the number of milliseconds as the buffer.

Edited by -Ultima-

[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

Share this post


Link to post
Share on other sites

Setting the timeout is possible for WinInet InternetConnect handles by using wininet.dll's InternetSetOption in conjunction with...

INTERNET_OPTION_CONNECT_TIMEOUT - for connection requests

INTERNET_OPTION_RECEIVE_TIMEOUT - for receiving request responses

INTERNET_OPTION_SEND_TIMEOUT - for sending requests

and passing a DWORD struct containing the number of milliseconds as the buffer.

Sorry, I tried several times to make this work, but without success. I'd be really grateful for a brief example...

Thanks

Chris

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Sorry, I tried several times to make this work, but without success. I'd be really grateful for a brief example...

Thanks

Chris

ive been trying and i havnt got it yet anyone know?

i would recomend that if you need this that you should migrate to useing the wininet wrapper udf i havnt tried it but i know that a function to use internetsetoption is included.

however i did some googling and i found some people saying that the timeout options have documented bugs, and whatever it was they were using them for it wouldnt have any effect.

Edited by JohnMC

Share this post


Link to post
Share on other sites

getsize cause autoit error.

$server = '128.232.104.10'

$username = 'anonymous'

$pass = ''

$Hand = _FTPOpen('Doesnt Matter')

$Ftpc = _FTPConnect($Hand, $server, $username, $pass)

if @error then

msgbox(0,"Error","Connect Error")

Exit

EndIf

$Ftpg = _FTPGetFileSize($Hand, '/index.htm')

$Ftpc = _FTPClose($Hand);Close ftp session

get autoit.exe error

AppName: autoit3.exe AppVer: 3.2.12.1 ModName: unknown

ModVer: 0.0.0.0 Offset: 0000000e

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Hey I'm having some trouble with these functions and cant seem to get them to work in my script for some reason. I'm a bit of a noob as u can tell by my my post count, so I might just be doing something stupid. Also I've tried other variations of these functions none seem to work for me. Any help would be great. Here's the code pertaining to the ftp:

#include <FTP.au3> ; yes this is the correct one just renamed it...

$file = 'C:\folderpath\' & @ComputerName & '_' & @MON & '_' & @MDAY & '.html' ; this already exists
$ftpfile = '/Files/' & @ComputerName & '_' & @MON & '_' & @MDAY & '.html'
$server = 'ftp.drivehq.com'
$username = 'MyUsername'
$pass = 'MyPass'

$handle = _FTPOpen('myftp')
 If @error Then
    MsgBox(0,'FTPOpen Error', @error)
 EndIf
$ftpc = _FTPConnect($handle, $server, $username, $pass)
 If @error Then
    MsgBox(0,'FTPConnect Error', @error)
 EndIf
 ;the code works up till this point
$ftpp = _FtpPutFile($handle, $file, $ftpfile)
 If @error Then
    MsgBox(0,'FTPPut Error', @error) ;this is where i get an error message
 EndIf
_FTPClose($handle)

Also if it makes any difference im using AutoIt v3.2.12.1 atm

Edited by GotX

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