tom13 Posted April 14, 2007 Share Posted April 14, 2007 (edited) Hey,I'm completely new to AutoIT. What I want is a script that will upload a file to some FTP address. This is what I copied from another script:expandcollapse popup_FTPConnect() _FTPPutFile() ;=============================================================================== ; ; Function Name: _FTPConnect() ; Description: Connects to an FTP server. ; Parameter(s): $l_InternetSession - The Long from _FTPOpen() ; $s_ServerName - Server name/ip. ; $s_Username - Username. ; $s_Password - Password. ; $i_ServerPort - Server port ( 0 is default (21) ) ; $l_Service - I dont got a clue what this does. ; $l_Flags - Special flags. ; $l_Context - I dont got a clue what this does. ; Requirement(s): DllCall, wininet.dll ; Return Value(s): On Success - Returns an indentifier. ; On Failure - 0 and sets @ERROR ; Author(s): Wouter van Kesteren ; ;=============================================================================== Func _FTPConnect($l_InternetSession, $s_ServerName = "xxx.xxx.xxx.xxx", $s_Username = "username", $s_Password = "password", $i_ServerPort = 0, $l_Service = 1, $l_Flags = 0, $l_Context = 0) 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() ;=============================================================================== ; ; Function Name: _FTPPutFile() ; Description: Puts an file on an FTP server. ; Parameter(s): $l_FTPSession - The Long from _FTPConnect() ; $s_LocalFile - The local file. ; $s_RemoteFile - The remote Location for the file. ; $l_Flags - Special flags. ; $l_Context - I dont got a clue what this does. ; Requirement(s): DllCall, wininet.dll ; Return Value(s): On Success - 1 ; On Failure - 0 ; Author(s): Wouter van Kesteren ; ;=============================================================================== Func _FTPPutFile($l_FTPSession = "long", $s_LocalFile = "text.txt", $s_RemoteFile = "log.txt", $l_Flags = 0, $l_Context = 0) Local $ai_FTPPutFile = DllCall('wininet.dll', 'int', 'FtpPutFile', 'long', $l_FTPSession, 'str', $s_LocalFile, 'str', $s_RemoteFile, 'long', $l_Flags, 'long', $l_Context) If @error OR $ai_FTPPutFile[0] = 0 Then SetError(-1) Return 0 EndIf Return $ai_FTPPutFile[0] EndFunc;==> _FTPPutFile()As it is now, it's not working. Can you help me to let this work please?So, I want text.txt to be uploaded to ftp://xxx.xxx.xxx.xxx when you open the script.Thanks in advance Edited April 14, 2007 by tom13 Link to comment Share on other sites More sharing options...
BrettF Posted April 14, 2007 Share Posted April 14, 2007 Hi Tom13, Welcome to the forums. With the functions, you need to use the parameters, like: _FTPConnect($l_InternetSession, $s_ServerName = "xxx.xxx.xxx.xxx", $s_Username = "username", $s_Password = "password", $i_ServerPort = 0, $l_Service = 1, $l_Flags = 0, $l_Context = 0) _FTPPutFile($l_FTPSession = "long", $s_LocalFile = "text.txt", $s_RemoteFile = "log.txt", $l_Flags = 0, $l_Context = 0) Try that and see how you go Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Developers Jos Posted April 14, 2007 Developers Share Posted April 14, 2007 don't forget to do a DllLoad() at the beginning and use the Handle returned or else will give problems. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
tom13 Posted April 14, 2007 Author Share Posted April 14, 2007 Hi Tom13, Welcome to the forums. With the functions, you need to use the parameters, like: _FTPConnect($l_InternetSession, $s_ServerName = "xxx.xxx.xxx.xxx", $s_Username = "username", $s_Password = "password", $i_ServerPort = 0, $l_Service = 1, $l_Flags = 0, $l_Context = 0) _FTPPutFile($l_FTPSession = "long", $s_LocalFile = "text.txt", $s_RemoteFile = "log.txt", $l_Flags = 0, $l_Context = 0) Try that and see how you go Thanks for your reply, but when I update it and run it I get this error: Error: Variable used without being declared. Please keep in mind that I know nothing about AutoIT so I'm probably doing something very newbies Link to comment Share on other sites More sharing options...
BrettF Posted April 14, 2007 Share Posted April 14, 2007 Thanks for your reply, but when I update it and run it I get this error: Error: Variable used without being declared. Please keep in mind that I know nothing about AutoIT so I'm probably doing something very newbies Ok, I think I should have made it a little clearer, my bad on my behalf. Just to make sure you have to do this: #Include <FTP.au3> $server = 'server.host.com' $username = 'username' $pass = 'password' $Open = _FTPOpen('MyFTP Control') $Conn = _FTPConnect($Open, $server, $username, $pass) If $Conn = 0 Then MsgBox (0, "Error", "Error!") EndIf $Ftpp = _FtpPutFile($Conn, 'FULL\PATH\TO\TEXT', '/text.txt') $Ftpc = _FTPClose($Open) I'm assuming you have the full FTP UDF bu w0uter in your script dir. So you declare those varibles at the top, and then open the connection. Now you connect to your FTP server, and the you check it for an error. Then you put your file and the close the connection. Thats it really. Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Zedna Posted April 14, 2007 Share Posted April 14, 2007 (edited) Ok, I think I should have made it a little clearer, my bad on my behalf. Just to make sure you have to do this: I'm assuming you have the full FTP UDF bu w0uter in your script dir. So you declare those varibles at the top, and then open the connection. Now you connect to your FTP server, and the you check it for an error. Then you put your file and the close the connection. Thats it really. As JDeB said you missed DllOpen/DllClose: and also Exit after error #Include <FTP.au3> $server = 'server.host.com' $username = 'username' $pass = 'password' $dllhandle = DllOpen('wininet.dll') $Open = _FTPOpen('MyFTP Control') $Conn = _FTPConnect($Open, $server, $username, $pass) If $Conn = 0 Then MsgBox (0, "Error", "Error!") Exit EndIf $Ftpp = _FtpPutFile($Conn, 'C:\FULL\PATH\TO\TEXT', '/text.txt') $Ftpc = _FTPClose($Open) DllClose($dllhandle) Edited April 14, 2007 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
BrettF Posted April 15, 2007 Share Posted April 15, 2007 Isn't that what _FTPOpen dose? (I'll see now ) Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
BrettF Posted April 15, 2007 Share Posted April 15, 2007 Isn't that what _FTPOpen dose? (I'll see now )Or not.... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Jazkal Posted April 15, 2007 Share Posted April 15, 2007 Zedna (or anybody), Would you happen to know the needed change in that example script to make a passive upload? Link to comment Share on other sites More sharing options...
Developers Jos Posted April 15, 2007 Developers Share Posted April 15, 2007 (edited) This is an updated FTPHandleFile() which will Upload a file to the given FTP server and uses the Dllopen Handle: Func FTPHandleFile($s_ServerName, $s_Username, $s_Password, $Source_File, $Target_File, $Transfer_Type) $h_FTP_Dll = DllOpen('wininet.dll') $Open = _FTPOpen($h_FTP_Dll, 'my ftp') If $Open <> 0 Then $Conn = _FTPConnect($h_FTP_Dll, $Open, $s_ServerName, $s_Username, $s_Password) If $Conn <> 0 Then $Ftpp = _FTPPutFile($h_FTP_Dll, $Conn, $Source_File, $Target_File, $Transfer_Type) If @error = 0 Then ConsoleWrite("File:" & $Source_File & " copied to:" & $Target_File & @LF) Return 1 Else ConsoleWrite("Error:" & $Ftpp & " Failed copying File:" & $Source_File & " to:" & $Target_File & @LF) Return 0 EndIf Else ConsoleWrite("Failed starting connection" & @LF) EndIf $Ftpc = _FTPClose($h_FTP_Dll, $Open) Else ConsoleWrite("Failed opening connection") EndIf DllClose($h_FTP_Dll) EndFunc ;==>FTPHandleFile Use attached Ftp.au3 which is a modified version of W0uter's posted version. Edited April 15, 2007 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Developers Jos Posted April 15, 2007 Developers Share Posted April 15, 2007 Zedna (or anybody), Would you happen to know the needed change in that example script to make a passive upload?Try this to see if that works: Update this in the previous posted example. $INTERNET_FLAG_PASSIVE= 0x08000000 $Conn = _FTPConnect($h_FTP_Dll, $Open, $s_ServerName, $s_Username, $s_Password,0,$INTERNET_FLAG_PASSIVE) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Zedna Posted April 15, 2007 Share Posted April 15, 2007 This is an updated FTPHandleFile() which will Upload a file to the given FTP server and uses the Dllopen Handle:Use attached Ftp.au3 which is a modified version of W0uter's posted version.I think better solution will be to add into FTP.au3 UDF DllOpen('wininet.dll'), so this DLL will be opened at start of whole script which has #include <ftp.au3>DllClose() will be automatically done by Autoit at end of script. So no need to make modified UDF with changed paramtres in every function Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
BrettF Posted April 15, 2007 Share Posted April 15, 2007 I think better solution will be to add into FTP.au3 UDF DllOpen('wininet.dll'), so this DLL will be opened at start of whole script which has #include <ftp.au3>DllClose() will be automatically done by Autoit at end of script. So no need to make modified UDF with changed paramtres in every functionor maybe in _FTPOpen/_FTPClose???? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Zedna Posted April 15, 2007 Share Posted April 15, 2007 or maybe in _FTPOpen/_FTPClose????Yes that's good idea.So in _FTPOpen().In _FTPClose() not because you have to make $dll_handle make as global variable (return from _FTPOpen()so it's simpler to just make DllOpen in _FTPOpen() and AutoIt automatically close Dll on script exit. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Developers Jos Posted April 15, 2007 Developers Share Posted April 15, 2007 Either way works, but you still should change W0uters UDF's to use the retuned Handle by DllLoad() in stead of "winInet.dll"... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Developers Jos Posted April 15, 2007 Developers Share Posted April 15, 2007 Come to think of it, I have been waiting for somebody to take the FTP.au3 UDFs and submit something that's worth putting in the standard UDF library .. Surprised nobody did that yet ... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now