Jump to content

FTP UDF (Updated 1-10)


JohnMC
 Share

Recommended Posts

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

sorry for the delay in response, i dont know if you figgured it out by now..

i dont see any issue in your code... does the remote folder "Files" with a uppercase F already exist, im not sure if all the same case rules apply with unix ftp servers as with http

have you tried using a simple example, without long file names, like _FtpPutFile($Hand, 'C:\ijustmadethis.txt', '/ijustmadethis.txt')

Link to comment
Share on other sites

  • Replies 45
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hello! Prompt please why functions _FTPFindFistFile (_FTPFileFindFist) _FTPFindNextFile (_FTPFileFindNext) do not return Creation Time Low, Creation Time Hight, Access Time Low, Access Time Hight, Last Write Low and Last Write Hight.

Link to comment
Share on other sites

  • 2 weeks later...

Can someone explain the FTPPutFile line? I'm trying to send a picture to my FTP with the new .FTP.au3 file but no luck

#include <file.au3>
#include <.FTP.au3>

$server = 'ftp.t35.com'
$username = 'xxxx.t35.com'
$pass = 'xxxx'

$Open = _FTPOpen('MyFTP')
$Conn = _FTPConnect($Open, $server, $username, $pass)
$Ftpp = _FtpPutFile($Conn, 'C:\Windows\picture.jpg', 'what goes here?')
$Ftpc = _FTPClose($Open)
Link to comment
Share on other sites

  • 2 weeks later...

Can someone explain the FTPPutFile line? I'm trying to send a picture to my FTP with the new .FTP.au3 file but no luck

#include <file.au3>
#include <.FTP.au3>

$server = 'ftp.t35.com'
$username = 'xxxx.t35.com'
$pass = 'xxxx'

$Open = _FTPOpen('MyFTP')
$Conn = _FTPConnect($Open, $server, $username, $pass)
$Ftpp = _FtpPutFile($Conn, 'C:\Windows\picture.jpg', 'what goes here?')
$Ftpc = _FTPClose($Open)
You just need to put the destination in there, eg '\picture.jpg' will put it in the current folder on the server.

BTW this is awesome, I've been trying to get the older version of FTP.au3 working without any luck. I got this version and ran the example and it worked straight away!!

Thank you, Thank you, Thank you :mellow:

Link to comment
Share on other sites

  • 2 weeks later...

_FTPPutFile always errors out on me after a short duration.

Here's the script:

Local $opt_FTP_Server = ""
Local $opt_FTP_Username = ""
Local $opt_FTP_Password = ""

$hFtp = _FTPOpen("FTPManadarX")
If @error Then _Err("FTPOpen error: " & @error)
_FTPConnect($hFtp, $opt_FTP_Server, $opt_FTP_Username, $opt_FTP_Password, 21, 1, 0x08000000)
If @error Then _Err("FTPConnect error: " & @error)
_FTPMakeDir($hFtp, "/public_html/test/")
If @error Then _Err("FTPMakeDir error: " & @error)
_FTPPutFile($hFtp,"C:\Documents and Settings\Jos\My Documents\AutoIt\Hooks.au3", "/public_html/test/hooks.au3")
If @error Then _Err("FTPPutFile error: " & @error)
_FTPClose($hFtp)
If @error Then _Err("FTPClose error: " & @error)

Func _Err($e)
    MsgBox(0,"Error!", $e)
    Exit
EndFunc

Edit: Fixed by connecting in passive mode. ( Can we possibly get a documentation update? )

Edited by Manadar
Link to comment
Share on other sites

  • 3 weeks later...

hello to all,

start to read this post from start but i've already some questions :

- see that is possible to list ftp directory ? with wich details (hour, filesize, etc) ?

- need this script to build program that every hour check ftp directory and download only new generated files, is possible ?

thank you for any reply,

m.

Link to comment
Share on other sites

hello to all,

start to read this post from start but i've already some questions :

- see that is possible to list ftp directory ? with wich details (hour, filesize, etc) ?

- need this script to build program that every hour check ftp directory and download only new generated files, is possible ?

thank you for any reply,

m.

Yes.

Search for _FtpFileFindFirst(), _FtpFileFindNext()

Link to comment
Share on other sites

download last source and modify test inside zip to understand usage, but i've some problem.

Please explain for now only download from given ftp.

My script:

#include <.ftp.au3>
#include <Array.au3>;only used for this test file to dispay the return value of the ftpfilefind function

$server = 'ftp.symantec.com'
$username = 'anonymous'
$pass = 'pass'

Local $RemoteDir = '/public/english_us_canada/antivirus_definitions/norton_antivirus/'
Local $LocalDir = "C:\TempDir\"
Local $Count = 0

;$Hand will be a handle in the form of an array containing multiple handles and information, and is the only handle referenced
$Hand = _FTPOpen('Doesnt Matter')

;In place of returning the "new" connect handle _FTPConnect like any other function will update the handle array already in use
;the return value will be as with any other function, 1 on success and 0 on failure
$Ftpc = _FTPConnect($Hand, $server, $username, $pass)
    if @error then 
        msgbox(0,"Error","Connect Error")
        Exit
    EndIf
    
;~ $Ftpp = _FtpPutFile($Hand, 'C:\WINDOWS\Notepad.exe', '/Example1.exe')
;~ $Ftpp = _FtpPutFile($Hand, 'C:\WINDOWS\Notepad.exe', '/Example2.exe')
;~ $Ftpm = _FTPMakeDir($Hand, 'ExampleFolder')
;~ $Ftpp = _FtpPutFile($Hand, 'C:\WINDOWS\Notepad.exe', '/ExampleFolder/Example3.exe')
;~ $Ftpg = _FTPGetFile($Hand, '/ExampleFolder/Example3.exe', @ScriptDir & '\Example3.exe')

$Ftpff= _FTPFileFindFirst($Hand,"*")
_ArrayDisplay($Ftpff)
$Ftpffn= _FTPFileFindNext($Hand)
_ArrayDisplay($Ftpffn)
$Ftpffn= _FTPFileFindNext($Hand)
_ArrayDisplay($Ftpffn)

$Ftpffc = _FTPFileFindClose($Hand);Close filefind session (Only one  _FTPFileFind can go on at a time so this must be used before using the _FTPGetFolderContents)

_FTPGetFolderContents($Hand,"",$LocalDir,1);Needs trailing slash backslash

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

for now i want to understand how download all content of REMOTEDIR '/public/english_us_canada/antivirus_definitions/norton_antivirus/'

in local folder.

Second step want to undestand how download new created files. (_FtpFileFindFirst(), _FtpFileFindNext())

Thank you any info,

m.

Edited by myspacee
Link to comment
Share on other sites

Sorry for ask again,

anyone can post script example for download directory content from ftp server ?

$server = 'ftp.symantec.com'
$username = 'anonymous'
$pass = 'pass'
$RemoteDir = '/public/english_us_canada/antivirus_definitions/norton_antivirus/'

thank you,

m.

Link to comment
Share on other sites

  • 3 weeks later...

Sorry for ask again,

anyone can post script example for download directory content from ftp server ?

$server = 'ftp.symantec.com'
$username = 'anonymous'
$pass = 'pass'
$RemoteDir = '/public/english_us_canada/antivirus_definitions/norton_antivirus/'

thank you,

m.

#include <.ftp.au3>
$server = 'ftp.symantec.com'
$username = 'anonymous'
$pass = 'pass'
$RemoteDir = '/public/english_us_canada/antivirus_definitions/norton_antivirus/'


$Hand = _FTPOpen('Doesnt Matter')
_FTPConnect($Hand, $server, $username, $pass)
_FTPGetFolderContents($Hand,$RemoteDir,@DesktopDir&"\ftp udf test\",1)

Side Note: Im now working on this UDF again, i know its full of issues, and id like to sort them out so please let me know what you experience. Also the wininet UDF is well worth it, and i recomend it, my udf is a shortcut it almost everyway and will be usefull for a quick and dirty script, but might not be dependable for something larger.

Link to comment
Share on other sites

  • 4 weeks later...

Hello all,

I am glad this excist so i can cover up the password and also automate my upload while i make the file.

But it doesn't work. I can connect but i cannot upload it with the _FtpPutFile

;i inserted the whole .ftp.au3 here
$server = 'server'
$username = 'user'
$pass = 'pass'


;$Hand will be a handle in the form of an array containing multiple handles and information, and is the only handle referenced
$Hand = _FTPOpen('Doesnt Matter')

_FTPConnect($Hand, $server, $username, $pass)
if @error then msgbox(0,"Error","Connect")

_FtpPutFile($Hand, 'c:\selectie.txt', '/subdomains/sub/httpdocs/selectie.txt');Upload to sub directory with different file name
if @error then msgbox(0,"Error","selectie.txt uploaden is niet gelukt")
    
_FTPClose($Hand);Close ftp session

i use AutoIt v3.3.0.0

and FTP UDF, Updated By JohnMC On Jan 10th 2009, TeamMC.cc

And i use this on a Windows 2000 machine and also on a 2003 SBS, but on both it doesn't work.

Anyobdy any idea? Cause i keep getting the Errorbox with ''selectie.txt uploaden is niet gelukt" (selectie.txt upload failed)

Edited by TobiasO
Link to comment
Share on other sites

When I attempt to download the latest file from your TeamMC site, it asks for a username and password?

Edit: Nevermind, I attempted it without my downloading plugin and it worked.

Edited by Sticky
Link to comment
Share on other sites

Well done, I used your UDF in their scripts. But why did you not use the functions InternetSetOption (for example, to set the timeout response from the FTP server). Without this script can not answer a long time. In my scripts I have used it. To set the timeout it will look like this:

const $INTERNET_OPTION_RECEIVE_TIMEOUT = 6

const $TimeOut = 60 * 1000 ; ms

local $WININET_HANDLE = DllOpen('wininet.dll')

_InternetSetOptions($hInternet, $INTERNET_OPTION_RECEIVE_TIMEOUT, $TimeOut)

func _InternetSetOptions($hInternet, $iOption, $iValue)
    
    local $tBuffer = DllStructCreate('int Value')
    
    DllStructSetData($tBuffer, 'Value', $iValue)
    DllCall($WININET_HANDLE, 'int', 'InternetSetOptionW', 'hwnd', $hInternet, 'int', $iOption, 'ptr', DllStructGetPtr($tBuffer), 'int', DllStructGetSize($tBuffer))
    $tBuffer = 0
    if (@error) or (_WinAPI_GetLastError() > 0) then
        return SetError(1, 0, 0)
    endif
    
    return SetError(0, 0, 1)
endfunc; _InternetSetOptions

The following list shows the options that can be set for $iOption:

INTERNET_OPTION_CONTEXT_VALUE

INTERNET_OPTION_CONNECT_TIMEOUT

INTERNET_OPTION_CONNECT_RETRIES

INTERNET_OPTION_CONNECT_BACKOFF

INTERNET_OPTION_CONTROL_SEND_TIMEOUT

INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT

INTERNET_OPTION_DATA_SEND_TIMEOUT

INTERNET_OPTION_DATA_RECEIVE_TIMEOUT

INTERNET_OPTION_READ_BUFFER_SIZE

INTERNET_OPTION_WRITE_BUFFER_SIZE

INTERNET_OPTION_USERNAME

INTERNET_OPTION_PASSWORD

INTERNET_OPTION_PROXY

INTERNET_OPTION_USER_AGENT

INTERNET_OPTION_RECEIVE_TIMEOUT

http://msdn.microsoft.com/en-us/library/ms918381.aspx

Edited by Yashied
Link to comment
Share on other sites

Well done, I used your UDF in their scripts. But why did you not use the functions InternetSetOption (for example, to set the timeout response from the FTP server). Without this script can not answer a long time. In my scripts I have used it. To set the timeout it will look like this:

const $INTERNET_OPTION_RECEIVE_TIMEOUT = 6

const $TimeOut = 60 * 1000 ; ms

local $WININET_HANDLE = DllOpen('wininet.dll')

_InternetSetOptions($hInternet, $INTERNET_OPTION_RECEIVE_TIMEOUT, $TimeOut)

func _InternetSetOptions($hInternet, $iOption, $iValue)
    
    local $tBuffer = DllStructCreate('int Value')
    
    DllStructSetData($tBuffer, 'Value', $iValue)
    DllCall($WININET_HANDLE, 'int', 'InternetSetOptionW', 'hwnd', $hInternet, 'int', $iOption, 'ptr', DllStructGetPtr($tBuffer), 'int', DllStructGetSize($tBuffer))
    $tBuffer = 0
    if (@error) or (_WinAPI_GetLastError() > 0) then
        return SetError(1, 0, 0)
    endif
    
    return SetError(0, 0, 1)
endfunc; _InternetSetOptions

The following list shows the options that can be set for $iOption:

INTERNET_OPTION_CONTEXT_VALUE

INTERNET_OPTION_CONNECT_TIMEOUT

INTERNET_OPTION_CONNECT_RETRIES

INTERNET_OPTION_CONNECT_BACKOFF

INTERNET_OPTION_CONTROL_SEND_TIMEOUT

INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT

INTERNET_OPTION_DATA_SEND_TIMEOUT

INTERNET_OPTION_DATA_RECEIVE_TIMEOUT

INTERNET_OPTION_READ_BUFFER_SIZE

INTERNET_OPTION_WRITE_BUFFER_SIZE

INTERNET_OPTION_USERNAME

INTERNET_OPTION_PASSWORD

INTERNET_OPTION_PROXY

INTERNET_OPTION_USER_AGENT

INTERNET_OPTION_RECEIVE_TIMEOUT

http://msdn.microsoft.com/en-us/library/ms918381.aspx

Great point, i should add this, but i help me out here... are there known issues with some options, most notably the timeout ones, i dont know if im getting this mixed up with a different project, but i remember people complaing about how it never worked right, thats why i never botherd

also should i set these constants within this UDF, and are the values based on the posistion they have in the list on the msdn

Edited by JohnMC
Link to comment
Share on other sites

  • 3 weeks later...

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...