MazeMiami Posted November 23, 2008 Share Posted November 23, 2008 (edited) Ok so i would like to make an auto it that can log on to my ftp and auto upload file i need 300+ files to go into 300 different dir. but i can't get autoit to upload anything i think the rest would be pretty easy but i am unable to connect here is what i got #include "FTP.au3" Dim $Handle, $DllRect $server = "toonrip.com"; Your FTP Server $username = "xxxx"; Your FTP username $pass = "xxxx"; FTP Password $Open = _FTPOpen("MyFTP",0); Starts up FTP services If @error Then Failed("Open"); If error, tell the user $Conn = _FTPConnect($Open, $server, $username, $pass, 21); Connect to server If @error Then Failed("Connect"); if error tell user $Ftpp = _FtpPutFile($Conn, "C:\TEST.txt", "/public_html/Autoit_Test"); Puts notepad into /somedir/ named as example.exe on your server If $ftpp = 0 Then MsgBox(0, " ", "Put file failed") endif $Ftpc = _FTPClose($Open); closes the FTP control ;===================== ; Error Function ;===================== Func Failed($error) MsgBox(48, 'Error', $error) Exit EndFunc Thanks! Edited November 23, 2008 by MazeMiami Link to comment Share on other sites More sharing options...
Zedna Posted November 23, 2008 Share Posted November 23, 2008 You missed: $dllhandle = DllOpen('wininet.dll') Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
MazeMiami Posted November 23, 2008 Author Share Posted November 23, 2008 (edited) You missed: $dllhandle = DllOpen('wininet.dll') thank for the reply i added it to the top of my script still get the connect error (not 100% sure were it goes did you mean $handel ?) do i need to download this dill or any thing else ? also does if go before the Dim, or after ? Edited November 23, 2008 by MazeMiami Link to comment Share on other sites More sharing options...
Zedna Posted November 23, 2008 Share Posted November 23, 2008 thank for the reply i added it to the top of my script still get the connect error (not 100% sure were it goes did you mean $handel ?)do i need to download this dill or any thing else ?also does if go before the Dim, or after ?Read whole FTP topic to see details about that. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
MazeMiami Posted November 23, 2008 Author Share Posted November 23, 2008 I have read several topics on FTP I have tried several different codes that have been posted here and I can't seem to get any of them to work I appreciate your help I will continue to read but I have had zero luck so far Thanks! Link to comment Share on other sites More sharing options...
MazeMiami Posted November 23, 2008 Author Share Posted November 23, 2008 i am able to connect !!! Having issue with put file looking into it now #include "FTP.au3" $hDll = DllOpen("Wininet.dll") $server = "toonrip.com"; Your FTP Server $username = "xxxx"; Your FTP username $pass = "xxxx"; FTP Password $Open = _FTPOpen("MyFTP",0); Starts up FTP services If @error Then Failed("Open"); If error, tell the user $Conn = _FTPConnect($Open, $server, $username, $pass, 21); Connect to server If @error Then Failed("Connect"); if error tell user $Ftpp = _FtpPutFile($Conn, "C:\TEST.txt", "/public_html/Autoit_Test"); Puts notepad into /somedir/ named as example.exe on your server If $ftpp = 0 Then MsgBox(0, " ", "Put file failed") endif $Ftpc = _FTPClose($Open); closes the FTP control DllClose($hDll) ;===================== ; Error Function ;===================== Func Failed($error) MsgBox(48, 'Error', $error) Exit EndFunc Link to comment Share on other sites More sharing options...
MazeMiami Posted November 23, 2008 Author Share Posted November 23, 2008 ok this should be correct but it's not working any ideas why this may be i can now connect but keep getting the error put file failed sorry fo all the post just dont get why i'm having such a hard time i read every post on the topic and dont see others having this new issue $Ftpp = _FtpPutFile($Conn, "C:\TEST.txt", "/public_html/gay/"); Puts notepad into /somedir/ named as example.exe on your server If $ftpp = 0 Then MsgBox(0, " ", "Put file failed") endif $Ftpc = _FTPClose($Open); closes the FTP control DllClose($hDll) ;===================== ; Error Function ;===================== Func Failed($error) MsgBox(48, 'Error', $error) Exit EndFunc Link to comment Share on other sites More sharing options...
MagnumXL Posted December 18, 2008 Share Posted December 18, 2008 My code creates a file on the server but the filesize is 0 bytes. I have tried this with documents, archives and executables. All with the same result. $hnd = _FTPOpen("abcdefghi") $Ftpc = _FTPConnect($hnd, $server, $username, $pass) If @error Then msgbox(0,"Error","Connect Error") Exit EndIf $Ftpp = _FtpPutFile($hnd, 'C:\409.txt', '/409.txt') If @error then Msgbox(0,"Error","PutFile Error") Exit EndIf $Ftpc = _FTPClose($hnd) Maybe its the same problem. Any help? Link to comment Share on other sites More sharing options...
sheeva Posted December 27, 2008 Share Posted December 27, 2008 Same here Link to comment Share on other sites More sharing options...
myspacee Posted December 27, 2008 Share Posted December 27, 2008 hello, apologize for use this post for my request, but try and try FTP.au3 and can't resolve some issue... Anyone have working FTP sync dowbload script around ? (download from FTP to local, and sync content) Thank you, m. Link to comment Share on other sites More sharing options...
FireFox Posted December 27, 2008 Share Posted December 27, 2008 @myspacee not hard to use : expandcollapse popup#include <Ftp.au3> Opt("GuiOnEventMode", 1) #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $DLL = DllOpen('wininet.dll') $win = GUICreate("FTP Connect example", 160, 160, -1, -1, -1, BitOR($WS_EX_APPWINDOW, $WS_EX_TOOLWINDOW)) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUICtrlCreateLabel("FTP server", 5, 5) $server = GUICtrlCreateEdit("", 5, 20, 150, 20, $ES_AUTOHSCROLL) GUICtrlCreateLabel("FTP username", 5, 50) $username = GUICtrlCreateEdit("", 5, 65, 150, 20, $ES_AUTOHSCROLL) GUICtrlCreateLabel("FTP password", 5, 95) $password = GUICtrlCreateInput("", 5, 110, 150, 20, $ES_AUTOHSCROLL + $ES_PASSWORD) GUICtrlCreateButton("CONNECT", 5, 135, 70, 20) GUICtrlSetOnEvent(-1, "_FTP") GUISetState(@SW_SHOW, $win) Func _Exit() _FTPClose('MyFTPControl') DllClose($DLL) Exit EndFunc ;==>_Exit Func _OnAutoItExit() _Exit() EndFunc ;==>_OnAutoItExit Func _FTP() $Open = _FTPOpen('MyFTPControl') $FTP = _FTPConnect($Open, GUICtrlRead($server), GUICtrlRead($username), GUICtrlRead($password)) If @error Then MsgBox(16, "FTP connexion error !", "Could not connect to ftp !") Else MsgBox(64, "FTP connected !", "Connected successfully to ftp !") EndIf EndFunc ;==>_FTP While 1 Sleep(250) WEnd Cheers, FireFox. Link to comment Share on other sites More sharing options...
myspacee Posted December 27, 2008 Share Posted December 27, 2008 Firefox thank you for working FTP connect script, but i'm not able to add code to : (2 different approach for local sync) - navigate trought fpt directory - list newer files (time based) - download them to local dir or - navigate trought fpt directory - download all files without overwrite my local If i give parameter, anyone can generare ftp sync Autoit script: $server = 'ftp.symantec.com' $username = 'anonymous' $pass = 'pass' Local $RemoteDir = '/public/english_us_canada/antivirus_definitions/norton_antivirus/' Local $LocalDir = "C:\TempDir\" Read in lot of post and around internet that sync remote FTP directory with local dir is not so easy as think... Thank you, m. Link to comment Share on other sites More sharing options...
FireFox Posted December 27, 2008 Share Posted December 27, 2008 @myspacee- navigate trought fpt directory_FTPFileFindFirstFile_FTPFileFindNextFile_FTPFileGetTimeCheers, FireFox. Link to comment Share on other sites More sharing options...
myspacee Posted December 27, 2008 Share Posted December 27, 2008 Thank you for your attention Firefox, so anyone pull ftp.au3 to its limit, can't find examples on forum or people that use it that think to write some example script for _FTPFileFindFirstFile, _FTPFileFindNextFile, _FTPFileGetTime, functions. I'm too noob and can't find freeware/customizable software around here. i find my mission for 2009 ! (became less noob, obviously) m. Link to comment Share on other sites More sharing options...
FireFox Posted December 27, 2008 Share Posted December 27, 2008 @myspaceei find my mission for 2009 !(became less noob, obviously) The best way for you to became less noob is to learn all functions of helpfile....I think its the best way (because I've done that) Cheers, FireFox. Link to comment Share on other sites More sharing options...
myspacee Posted December 27, 2008 Share Posted December 27, 2008 then I hope ftp.au3 enter officially in help file ! m. Link to comment Share on other sites More sharing options...
FireFox Posted December 27, 2008 Share Posted December 27, 2008 @myspacee Here are functions you want : expandcollapse popupFunc _FTPListFiles($l_FTPSession, $l_Flags = 0, $l_Context = 0) $str = "dword;int64;int64;int64;dword;dword;dword;dword;char[256];char[14]" $WIN32_FIND_DATA = DllStructCreate($str) Local $callFindFirst = DllCall('wininet.dll', 'int', 'FtpFindFirstFile', 'long', $l_FTPSession, 'str', "", 'ptr', DllStructGetPtr($WIN32_FIND_DATA), 'long', $l_Flags, 'long', $l_Context) If Not $callFindFirst[0] Then MsgBox(0, "Folder Empty", "No Files Found ") SetError(-1) Return 0 EndIf $ret = "" While 1 If DllStructGetData($WIN32_FIND_DATA, 1) <> 16 Then $ret = $ret & DllStructGetData($WIN32_FIND_DATA, 9) & "|" Local $callFindNext = DllCall('wininet.dll', 'int', 'InternetFindNextFile', 'long', $callFindFirst[0], 'ptr', DllStructGetPtr($WIN32_FIND_DATA)) If Not $callFindNext[0] Then ExitLoop EndIf WEnd $WIN32_FIND_DATA = 0 Return StringTrimRight($ret, 1) EndFunc ;==>_FTPListFiles ;=============================================================================== ; Function Name: _FTPFindFirstFile() ; Description: Returns a search handle to be used with _FTPFindNextFile() ; Parameter(s): $hConnect - The long from _FTPConnect() ; $lpszSearchFile - The remote Location for the file. ; $dwFlags - 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). ; $dwContext - lContext is used to identify the application context when using callbacks (Default: 0) ; Requirement(s): DllCall, wininet.dll ; Return Value(s): On Success - Returns Search Handle ; On Failure - 0; Sets @error = -1 ; Comments: Tested with Current Remote Directory only, use _FtpSetCurrentDir() to change directory before calling _FTPFindFirstFile() ; Remember to call _FTPClose($SearchHwnd) to close the search handle ;=============================================================================== Func _FTPFindFirstFile($hConnect, $lpszSearchFile = "",$dwFlags = 0, $dwContext = 0) $WIN32_FIND_DATA = DllStructCreate($s_WIN32_FIND_DATA) Local $ai_FTPFirstFile = DllCall('wininet.dll', 'hwnd', 'FtpFindFirstFile', _ 'long', $hConnect, _ ;HINTERNET hConnect 'str', $lpszSearchFile, _ ;LPCTSTR lpszSearchFile 'ptr',DllStructGetPtr($WIN32_FIND_DATA), _ ;LPWIN32_FIND_DATA lpFindFileData 'long',$dwFlags, _ ;DWORD dwFlags 'long', $dwContext) ;DWORD_PTR dwContext If @error OR $ai_FTPFirstFile[0] = 0 Then SetError(-1) Return 0 EndIf Return $ai_FTPFirstFile[0] EndFunc ;==> _FTPFindFirstFile() ;=============================================================================== ; Function Name: _FTPFindNextFile() ; Description: Find Next File on an FTP server. ; Parameter(s): $hFind - The search hwnd returned by _FTPFindFirstFile() ; $sFilter - Search Filter (Default = "*.*"). ; $sFlag - 0(Default) Return both files and folders names ; - 1 Return file names only (Folders are returned as -1) ; - 2 Return folder names only (Files are returned as -1) ; - 3 Return Attributes Array (includes file/folder name) ; Requirement(s): DllCall, wininet.dll ; Return Value(s): On Success - Filename or Attributes Array ; On Failure - Last Filename or Attributes Array and @error = -1 ;=============================================================================== Func _FTPFindNextFile($hFind,$sFilter = "*.*", $sFlag = 0) Local $LastFilename Local $FileAttributes = DllStructGetData($WIN32_FIND_DATA, 1) ; File Attributes Switch $sFlag Case 0 $LastFilename = DllStructGetData($WIN32_FIND_DATA, 9) Case 1 If $FileAttributes <> $FILE_ATTRIBUTE_DIRECTORY Then $LastFilename = DllStructGetData($WIN32_FIND_DATA, 9) Else $LastFilename = -1 EndIf Case 2 If $FileAttributes == $FILE_ATTRIBUTE_DIRECTORY Then $LastFilename = DllStructGetData($WIN32_FIND_DATA, 9) Else $LastFilename = -1 EndIf Case 3 Local Const $MAXDWORD = 4294967295 Dim $a_FTPFileList[8] $a_FTPFileList[0] = 7 $a_FTPFileList[1] = DllStructGetData($WIN32_FIND_DATA, 1) ; File Attributes $FILETIME = DllStructCreate("dword;dword") DllStructSetData($FILETIME, 1, DllStructGetData($WIN32_FIND_DATA, 2, 1)); Creation Time Low DllStructSetData($FILETIME, 2, DllStructGetData($WIN32_FIND_DATA, 2, 2)); Creation Time High $a_FTPFileList[2] = _FileTimeToSystemTime(DllStructGetPtr($FILETIME)) $FILETIME = 0 $FILETIME = DllStructCreate("dword;dword") DllStructSetData($FILETIME, 1, DllStructGetData($WIN32_FIND_DATA, 3, 1)); Access Time Low DllStructSetData($FILETIME, 2, DllStructGetData($WIN32_FIND_DATA, 3, 2)); Access Time High $a_FTPFileList[3] = _FileTimeToSystemTime(DllStructGetPtr($FILETIME)) $FILETIME = 0 $FILETIME = DllStructCreate("dword;dword") DllStructSetData($FILETIME, 1, DllStructGetData($WIN32_FIND_DATA, 4, 1)); Last Write Time Low DllStructSetData($FILETIME, 2, DllStructGetData($WIN32_FIND_DATA, 4, 2)); Last Write Time High $a_FTPFileList[4] = _FileTimeToSystemTime(DllStructGetPtr($FILETIME)) $FILETIME = 0 ;The size of the file is equal to (nFileSizeHigh * (MAXDWORD+1)) + nFileSizeLow $a_FTPFileList[5] = (DllStructGetData($WIN32_FIND_DATA, 5) * ($MAXDWORD + 1)) + DllStructGetData($WIN32_FIND_DATA, 6) $a_FTPFileList[6] = DllStructGetData($WIN32_FIND_DATA, 9); File Name $a_FTPFileList[7] = DllStructGetData($WIN32_FIND_DATA, 10) ; Altername ;~ _ArrayDisplay($a_FTPFileList,"$a_FTPFileList") EndSwitch Local $ai_FTPNextFile = DllCall('wininet.dll', 'int', 'InternetFindNextFile', _ 'long', $hFind, _ ;HINTERNET hFind 'ptr',DllStructGetPtr($WIN32_FIND_DATA)) ;LPVOID lpvFindData If @error OR $ai_FTPNextFile[0] = 0 Then $WIN32_FIND_DATA = 0 ;free memory SetError(-1) If $sFlag == 3 Then Return $a_FTPFileList Else Return $LastFilename EndIf EndIf If $sFlag == 3 Then Return $a_FTPFileList Else Return $LastFilename EndIf EndFunc ;==> _FTPFindNextFile() Im working on it, if that work I'll give you some examples. Cheers, FireFox. Link to comment Share on other sites More sharing options...
FireFox Posted December 27, 2008 Share Posted December 27, 2008 (edited) Working on functions....FTPExtended (by ProgAndy) : FTP_Ex.au3 Edited December 27, 2008 by FireFox Link to comment Share on other sites More sharing options...
ProgAndy Posted December 27, 2008 Share Posted December 27, 2008 This one should include all necessary code http://www.autoit.de/index.php?page=Thread&postID=48393 *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
FireFox Posted December 27, 2008 Share Posted December 27, 2008 @ProgAndy Can you explain me how this functions works : _FTPFilesListToArray _FTPFileFindFirst _FTPFileFindNext Because it seems to dont work... expandcollapse popup#include <FTP_Ex.au3> Opt("GuiOnEventMode", 1) #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $DLL = DllOpen('wininet.dll') Local $h_Handle, $l_DllStruct #Region FTP-GUI CONNECT $win = GUICreate("FTP Connect example", 160, 160, -1, -1, -1, BitOR($WS_EX_APPWINDOW, $WS_EX_TOOLWINDOW)) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUICtrlCreateLabel("FTP server", 5, 5) $server = GUICtrlCreateEdit("", 5, 20, 150, 20, $ES_AUTOHSCROLL) GUICtrlCreateLabel("FTP username", 5, 50) $username = GUICtrlCreateEdit("", 5, 65, 150, 20, $ES_AUTOHSCROLL) GUICtrlCreateLabel("FTP password", 5, 95) $password = GUICtrlCreateInput("", 5, 110, 150, 20, $ES_AUTOHSCROLL + $ES_PASSWORD) GUICtrlCreateButton("CONNECT", 5, 135, 150, 20) GUICtrlSetOnEvent(-1, "_FTP") GUISetState(@SW_SHOW, $win) #EndRegion FTP-GUI CONNECT #Region FTP-GUI LIST $win = GUICreate("FTP List Files example", 160, 160, -1, -1, -1, BitOR($WS_EX_APPWINDOW, $WS_EX_TOOLWINDOW)) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState(@SW_HIDE, $win) #EndRegion FTP-GUI LIST Func _Exit() _FTPClose('MyFTPControl') DllClose($DLL) Exit EndFunc ;==>_Exit Func _OnAutoItExit() _FTPClose('MyFTPControl') DllClose($DLL) EndFunc ;==>_OnAutoItExit Func _FTP() $Open = _FTPOpen('MyFTPControl') $FTP = _FTPConnect($Open, GUICtrlRead($server), GUICtrlRead($username), GUICtrlRead($password)) If @error Then TrayTip("FTP Example", "Could not connect to ftp !", 2, 2) Else TrayTip("FTP Example", "Connected to ftp !", 2, 1) GUISetState(@SW_HIDE, $win) MsgBox(64, "_FTPListFiles", _FTPFilesListToArray('MyFTPControl')) MsgBox(64, "_FTPFindFirstFile", _FTPFileFindFirst('MyFTPControl', '', $h_Handle, $l_DllStruct)) MsgBox(64, "_FTPFindNextFile", _FTPFileFindNext('MyFTPControl', $l_DllStruct)) EndIf EndFunc ;==>_FTP While 1 Sleep(250) WEnd 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