Jump to content

FTP.au3


w0uter
 Share

Recommended Posts

I really like the idea of searching an FTP site...

FtpOpenFile supports:
FtpFindFirstFile
FtpFindNextFile

What are the possibilites of FXP using the wininet.dll functions instead of AutoIt's built-in FTP functions? I'm looking for the passive mode FTP stuff in MSDN, but haven't found it yet.

What about using the FtpOpenFile for reads and writes? It appears to provide "live" writing to a file versus creating a temp file and uploading it.

Link to comment
Share on other sites

  • Replies 283
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I really like the idea of searching an FTP site...

will do ... later.

What are the possibilites of FXP using the wininet.dll functions instead of AutoIt's built-in FTP functions?

what do you mean ? autoit doesnt even have build in ftp functions.

What about using the FtpOpenFile for reads and writes?  It appears to provide "live" writing to a file versus creating a temp file and uploading it.

maby later.

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

  • 2 weeks later...

AFAIK it automaticly detect's Settings if 0.

[edit]

0 = INTERNET_OPEN_TYPE_PRECONFIG = Retrieves the proxy or direct configuration from the registry.

[/edit]

Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

Still don't get it.

Tried to doi that way:

ftp.au3 :

RunWait(@ComSpec & " /c " & "ftp -s:c:\ftp.txt", "", @SW_HIDE)

ftp.txt :

open myhost.com
username
password
put c:\mydir\myfile path_on_server/myfile
put c:\mydir\myfile path_on_server/myfile
close
bye

When I run ftp -s:c:\ftp.txt from command line - everything works.

When I run the above au3 script with one string there - weird things happens:

Icon of AutoIt begins to multiply and computer runs out of memory.

Why???? :whistle::dance::dance:

Link to comment
Share on other sites

silly question. but, are you talking about the old version ?

if so you should really try the new version.

<{POST_SNAPBACK}>

Sorry, w0uter

I got to the wrong topic. In the last example I haven't use your function.

Just RunWait command and windows command line stuff.

When I used your function I could see the following ( I try to upload 2 files permanently with very short breaks): one file is OK and another with some temporary name pro-ftp... is not available from the web. Probably some proble of synchronization. But I really need that two ( or more files ) are being repeatedly uploaded and in the same time be available from the Internet.

Link to comment
Share on other sites

man.. many thanks.. i just had a client ask me for a basic utility to upload a file via ftp. This knocked it out in no time. Many thanks,

Damon

i thought my old _FTPxxx.au3 sucked.

so i tryd using STD for it. but it failed.

googled a bit and came across an vb site that used a windows dll,

then i headed over to msdn to find out how to use em.

this is the (unfinished) result.

i am still writing alot of docs for it.

since i want it included standardly.

but i got sick of it and just decided to get some feedback first.

[edit]

uploaded a new version.

for reference the old one got dl'ed 88 times.

[/edit]

[edit2]

uploaded a new version.

the other one wasnt even working.

why didnt you guys say anything :whistle:

for reference the semi-old one got dl'ed 269 times.

[/edit2]

<{POST_SNAPBACK}>

Link to comment
Share on other sites

Thanks, w0uter, this is wonderful extension that will hopefully make it into the official AutoIt source given its usefulness. However, I was in a situation that required passive FTP rather than the default active, and was rather dismayed when I read that this capability doesn't yet exist.

So, I started doing some research, and I was able to get passive FTP working as documented here:

http://msdn.microsoft.com/library/default....rnetconnect.asp

http://msdn.microsoft.com/library/default....t/api_flags.asp

Basically, I added another variable to _FTPConnect() to specifiy whether or not it should be passive. The new _FTPConnect() function is pasted below, as is an updated example. Right now this fourth argument is required, but I suspect it could be made optional so that, for example, it'll be active by default if the fourth argument isn't specified. Just wasn't able to get that working in my initial testing. I'm sure w0uter can figure this out if he chooses to add these modifications to his official extension.

Thanks again. Here are my changes

FTP.au3

Func _FTPConnect($l_InternetSession, $s_ServerName, $s_Username, $s_Password, $i_Passive, $i_ServerPort = 0, $l_Service = 1, $l_Flags = 0, $l_Context = 0)

    If $i_Passive == 1 then $l_Flags = 0x08000000
    Local $ai_InternetConnect = DllCall('wininet.dll', 'long', 'InternetConnect', 'long', $l_InternetSession, 'str', $s_ServerName, 'int', $i_ServerPort, 'str', $s_Username, 'str', $s_Password, 'long', $l_Service, 'long', $l_Flags, 'long', $l_Context)

    If @error OR $ai_InternetConnect[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf

    Return $ai_InternetConnect[0]

EndFunc;==> _FTPConnect()

FTP_Example.au3

#include <FTP.au3>
$server = 'ftp.server.com'
$username = 'username'
$pass = 'password'
$uploaddir = '/incoming/'

; New passive flag
; 0 = active, 1 = passive
$passive = 1

$Open = _FTPOpen('MyFTP Control')
$Conn = _FTPConnect($Open, $server, $username, $pass, $passive)
$Ftpp = _FtpPutFile($Conn, 'C:\WINNT\NOTEPAD.EXE', $uploaddir & 'notepad.exe')
$Ftpc = _FTPClose($Open)
Edited by nitro322
Link to comment
Share on other sites

Hi wOuter, maybe being stupid here, but is there no _FTPGet?

<{POST_SNAPBACK}>

Until w0ter releases his next version maybe you can use this:

;===============================================================================
;
; Function Name:    _FTPGetFile() - db Test
; Description:    Gets an file from an FTP server.
; Parameter(s):  $l_FTPSession  - The Long from _FTPConnect()
;                  $s_RemoteFile      - The remote Location for the file.
;                  $s_LocalFile     - The local file.
;                  $l_Flags     - use the dwFlags parameter to specify
;                                  -    1 for transferring the file in ASCII (Type A transfer method) or 
;                                  -    2 for transferring the file in Binary (Type I transfer method).
;                  $l_Fail       - Allow local file to be overwritten if it exists
;                                  -   -1 Don't allow overwrite (default)
;                                  -    0 Allow overwrite
;                  $l_Attributes   - Attributes for local file
;                  $l_Context     - lContext is used to identify the application context when using callbacks. Since were not using callbacks well pass 0.
; Requirement(s):   DllCall, wininet.dll
; Return Value(s):  On Success - 1
;                  On Failure - 0
; Author(s):        Dick Bronsdijk
;
;===============================================================================

Func _FTPGetFile($l_FTPSession, $s_RemoteFile, $s_LocalFile, $l_Flags = 2, $l_Fail = -1, $l_Attributes = 0, $l_Context = 0)

    Local $ai_FTPGetFile = DllCall('wininet.dll', 'int', 'FtpGetFile', 'long', $l_FTPSession, 'str', $s_RemoteFile, 'str', $s_LocalFile, 'long', $l_Fail, 'long', $l_Attributes, 'long', $l_Flags, 'long', $l_Context)
    If @error OR $ai_FTPGetFile[0] = 0 Then
        SetError(-1)
        Return 0
    EndIf
    
    Return $ai_FTPGetFile[0]
    
EndFunc;==> _FTPGetFile()
Link to comment
Share on other sites

instead of modding my function you could have called it with 0x08000000 as the $l_flags parameter

<{POST_SNAPBACK}>

Well, yeah, but 0x08000000 isn't the easiest thing to remember. ;) I figured just enabling a flag to tell AutoIt whether or not to use Passive FTP would be the easiest thing to do, especially if redistributing the code. Edited by nitro322
Link to comment
Share on other sites

  • 3 weeks later...

If @error OR $ai_InternetOpen[0] = 0 Then

SetError(-1)

Return 0

EndIf

sets the @error macro to -1 at failure, so to check if a function has failed do something like this:

_FtpOpen()

If @error <> -1 then

msgbox(0, '', 'failed')

exit

endIf

msgbox(0, '', 'sucess')

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

I cannot get this thing to work at all.

i used the example script and modified the server, login and password stuff.

but basically, i see it connecting, it then just dis-connects and doesnt transfer any files.

i've tried this with 2 diff. ftp servers..

even when i take out the ftp disconnect command. it still does it.

if i use a regular ftp client, everything works fine with both servers.

i'd post code, but like i said, i'm just using the provided example to test with.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...