Dracil Posted December 17, 2009 Posted December 17, 2009 Hello ive been reading through the topics on ftp and all i find is scripts and simply upload files with ftp like #Include <FTP.au3 > $server = '' $username = '' $pass = '' $Open = _FTPOpen('MyFTP Control') $Conn = _FTPConnect($Open, $server, $username, $pass) $Ftpp = _FtpPutFile($Conn, @ScriptDir & '\files\', 'obr.jpg') $Ftpc = _FTPClose($Open) But what is the function to actually download a file with ftp ? Thanks in advance
ichigo325 Posted December 17, 2009 Posted December 17, 2009 (edited) But what is the function to actually download a file with ftp?InetGet - Downloads a file from the internet using the http or ftp protocol. Edited December 17, 2009 by ichigo325 [size="2"][font="Lucida Sans Unicode"][b][/b][/font][/size]
jvanegmond Posted December 17, 2009 Posted December 17, 2009 I just had a crazy idea. Maybe if the function to put a file is _FtpPutFile ...Then the function get a file is .. _FtpGetFile.WHAT DO I WIN? github.com/jvanegmond
Dracil Posted December 17, 2009 Author Posted December 17, 2009 I just had a crazy idea. Maybe if the function to put a file is _FtpPutFile ...Then the function get a file is .. _FtpGetFile.WHAT DO I WIN?Yeah but such funtion does not exist in the FTP.au3
jvanegmond Posted December 17, 2009 Posted December 17, 2009 (edited) Ugh, it does if you pick the right version of FTP.au3 and not the ancient on by wouter.... http://www.autoitscript.com/forum/index.php?showtopic=78378Merry Christmas. Edited December 17, 2009 by Manadar github.com/jvanegmond
BitByteBit Posted December 17, 2009 Posted December 17, 2009 Here is a script I made for managing my FTP server. Enjoy. Also. . . Merry Christmas =D expandcollapse popup#include <FTP.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> Opt("TrayIconDebug", 1) ;opt("WinTitleMatchMode",3) ProcessSetPriority(@AutoItPID,3) HotKeySet("!z", "OpenCMD") HotKeySet("!{Esc}", "Exit1") HotKeySet("!{F4}", "Exit2") $FU = "INTERNET_FLAG_TRANSFER_BINARY" $Flag = "INTERNET_FLAG_RELOAD" Global $FileName[1] Global $FileName1[1] $Connected = False $Clicked = 0 $DummyCheck = "" #Region Login Global $hFtp, $hSession, $hFile, $tBuffer, $nSize, $nBytes Const $Host = 'yoursitehere.com' const $Login = 'anonymous' const $Password = 'pass' #EndRegion Login #Region GUI $FTP = GUICreate("File Server", 332, 285, 192, 124, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE)) GUISetBkColor(0x99B4D1) $Status = GUICtrlCreateLabel("Not Connected", 0, 5, 125, 15, $SS_CENTER) $Active = GUICtrlCreateLabel("Current Directory:", 115, 5, 86, 17) $ActiveDir = GUICtrlCreateLabel("Not Connnected", 205, 5, 300, 17) $Connect = GUICtrlCreateButton("Connect", 248, 20, 75, 33, $WS_GROUP) $Disconnect = GUICtrlCreateButton("Disconnect", 248, 100, 75, 33, $WS_GROUP) $List1 = GUICtrlCreateList("", 8, 20, 233, 149) $Put = GUICtrlCreateInput("", 8, 257, 233, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL)) GUICtrlSetState(-1, $GUI_ACCEPTFILES) $Upload = GUICtrlCreateButton("Upload", 246, 255, 78, 25, $WS_GROUP) $Back = GUICtrlCreateButton("Back", 248, 58, 75, 33, $WS_GROUP) $CMD = GUICtrlCreateButton("CMD", 247, 137, 75, 33, $WS_GROUP) $LogLable = GUICtrlCreateLabel("Log: ", 112, 170, 28, 17) $Log = GUICtrlCreateEdit("", 8, 192, 313, 49, BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN,$WS_VSCROLL)) GUISetState(@SW_SHOW) ;Delete Menu GUICtrlCreateContextMenu($List1) $delete = GUICtrlCreateMenuItem("&Delete", $List1) GUICtrlSetOnEvent(-1, "Delete") GUICtrlCreateContextMenu($List1) $Link = GUICtrlCreateMenuItem("&Get Link", $List1) GUICtrlSetOnEvent(-1, "GetLink") #EndRegion ; ; While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Disconnect() Exit Case $CMD OpenCMD() Case $Back Back() Case $Connect Connect() Case $Disconnect Disconnect() Case $List1 $Check = GUICtrlRead($List1) $FileName = StringSplit($Check, '.', 1) If Not @error Then $Clicked = $Clicked + 1 If $Clicked > 1 And $Check = $DummyCheck Then DownloadFile() $Clicked = 0 Else $DummyCheck = $Check EndIf Else CD() $Path = _FTP_GetCurrentDir($hSession) GUICtrlSetData($ActiveDir, $Path) $Clicked = 0 EndIf Case $Upload $Read = GUICtrlRead($Put) If $Read <> "" Then $FileName = StringSplit($Read, '\', 1) $FileName1 = UBound($FileName) - 1 $Array1 = $FileName[$FileName1] Upload() Else MsgBox(0, "!", "Please drag a file into the Input Box") EndIf Case $delete Delete() Case $Link GetLink() ;GetFileList() EndSwitch WEnd Func GetLink() $Path = _FTP_GetCurrentDir($hSession) $FileName12 = GUICtrlRead($List1) Select Case $Path = "/FileServer" $Log1 = @CRLF & GUICtrlRead($log) $Link1 = "http://http://www.YourSiteHere.com/FileServer/"&$FileName12 GUICtrlSetData($Log, "Copied to clipboard:"&@CRLF& "http://http://www.YourSiteHere.com/FileServer/"&$FileName12 &$log1 ) ClipPut($Link1) Case $Path = "/" $Link1 = "ftp://http://www.YourSiteHere.com/"&$FileName12 ClipPut($Link1) $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($Log, "Copied to clipboard:"&@CRLF& "ftp://http://www.YourSiteHere.com/"&$FileName12 &$log1 ) Case $Path = "/FTP" $Link1 = "ftp://http://www.YourSiteHere.com/FTP/"&$FileName12 ClipPut($Link1) $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($Log, "Copied to clipboard:"&@CRLF& "ftp://http://www.YourSiteHere.com/FTP"&$FileName12 &$log1 ) case Else $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($Log, "Unable to get link for: "&$FileName12&@CR&"Probable cause: Wrong Directory" &$log1 ) EndSelect EndFunc Func Delete() $Check = GUICtrlRead($List1) $Path = _FTP_GetCurrentDir($hSession) ;$File123 = $Path & "/" & $Check $Ques = MsgBox(4, "?", "Do you want to delete: " & $Path & "/" & $Check) If $Ques = 6 Then $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($Log, "Deleting File: "&$Path & "/" & $Check&$log1) _FTP_DeleteFile($hSession, $Check) If Not @error Then GUICtrlSetData($List1, "") GetFileList() $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($Log, "File: "&$Path & "/" & $Check&" has been deleted."&$log1) $Clicked = 0 Else $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($Log, "Unable to delete : "&$Path & $Check&$Log1) EndIf EndIf If $Ques = 7 Then Sleep(10) $Clicked = 0 EndIf EndFunc ;==>Delete Func Back() $Path = _FTP_GetCurrentDir($hSession) $FileName = StringSplit($Path, '/', 2) $FileName1 = UBound($FileName, 1) - 1 $FileName1 = $FileName1 - 1 $Array1 = $FileName[$FileName1] _FTP_SetCurrentDir($hSession, '/' & $Array1&"/") GUICtrlSetData($List1, "") GetFileList() $Path = _FTP_GetCurrentDir($hSession) GUICtrlSetData($ActiveDir, $Path) $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($Log, "Went up one directory to: "& $Path & $log1) EndFunc ;==>Back Func CD() $Path = _FTP_GetCurrentDir($hSession) _FTP_SetCurrentDir($hSession, $Path & '/' & $Check) GUICtrlSetData($List1, "") Sleep(250) GetFileList() $Log1 = @CRLF & GUICtrlRead($log) $Path = _FTP_GetCurrentDir($hSession) GUICtrlSetData($Log, "Changed folder to: "& $Path & $log1 ) EndFunc ;==>CD Func Connect() if $Connected = False Then _FTP_Startup() $hFtp = _FTP_Open('MyFtp') $hSession = _FTP_Connect($hFtp, $Host, $Login, $Password) If Not @error Then GUICtrlSetData($Log, "Connected to YourSiteHere.com") $Log1 = @CRLF & GUICtrlRead($log) Else GUICtrlSetData($Log, "Unable to Connect to: YourSiteHere.com") EndIf _FTP_SetCurrentDir($hSession, '/aftp') If Not @error Then GetFileList() GUICtrlSetData($Status, "Connected") $Path = _FTP_GetCurrentDir($hSession) GUICtrlSetData($ActiveDir, $Path) GUICtrlSetData($Log, "Changed folder to: /aftp/" & $log1 ) EndIf $Connected = True Else $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($Log, "Already connected"&$log1) EndIf EndFunc ;==>Connect Func GetFileList() GUICtrlSetData($List1,"") $Path = _FTP_GetCurrentDir($hSession) $tFind = DllStructCreate($tagWIN32_FIND_DATA) $hFind = _FTP_FileFindFirst($hSession, '', $tFind,$INTERNET_FLAG_RELOAD) _FTP_FileFindNext($hFind, $tFind) _FTP_FileFindNext($hFind, $tFind) while not @error $Data = DllStructGetData($tFind, 'FileName'); & @CR GUICtrlSetData($List1,$Data) _FTP_FileFindNext($hFind, $tFind) wend _FTP_FileFindClose($hFind) EndFunc Func Upload() $Status1 = GUICtrlRead($Status) If $Status1 = "Not Connected" Then Connect() EndIf ;GUICtrlSetData($Status, "Uploading: " & $Array1) $Path = _FTP_GetCurrentDir($hSession) $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($Log, "Uploading file: "&$Array1&" | "&"To: "&$Path&"/"&$log1) _FTP_PutFile($hSession,$Read, $Array1, $FU) If Not @error Then GetFileList() $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($Log, "Successfully Uploaded file "&$Array1&" | "&"To: "&$Path&"/"&$log1) Else $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($Log,"Unable to Upload file " & $Array1&$log1) EndIf EndFunc ;==>Upload Func DownloadFile() $Selection = GUICtrlRead($List1) GUICtrlSetData($Status, "Downloading. . .") $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($Log,"Please wait. . ."&@CRLF&"Downloading:"&@DesktopDir & '\' & $Selection&$Log1) _FTP_GetFile($hSession, $Selection, @DesktopDir & '\' & $Selection) If Not @error Then $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($Log, "Successfully Downloaded: "&@DesktopDir & '\' & $Selection&$Log1) ShellExecute(@DesktopDir & '\' & $Selection) if not @error Then $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($Log, "Successfully Opened: "&@DesktopDir & '\' & $Selection&$Log1) EndIf Else $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($Log, "Unsuccessfully Downloaded: "&$Selection&$Log1) ;ToolTip("Unable to download file: " & $Selection) EndIf GUICtrlSetData($Status, "Connected") EndFunc ;==>DownloadFile Func Disconnect() _FTP_Disconnect($hSession) _FTP_Close($hFtp) _FTP_Shutdown() $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($log,"Disconnected"&$log1) GUICtrlSetData($Status, "Not Connected") GUICtrlSetData($List1, "") GUICtrlSetData($ActiveDir, "Not Connected") ;Exit] $Connected = False EndFunc ;==>Disconnect Func OpenCMD() $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($Log, "Opening CMD"&$log1) If $Connected = False Then ShellExecute("cmd", "/t:0a /k ftp YourSiteHere.com") If Not WinActive("C:\Windows\System32\cmd.exe - ftp YourSiteHere.com") Then WinActivate("C:\Windows\System32\cmd.exe - ftp YourSiteHere.com") WinWait("C:\Windows\System32\cmd.exe - ftp YourSiteHere.com") EndIf Sleep(2000) Send("anonymous{enter}") ;Login Sleep(150) Send("Anonymous@YourSiteHere.com{enter}") ;Password Sleep(275) Send("cd /FTP{enter}") Sleep(275) Send("dir{enter}") Else $Log1 = @CRLF & GUICtrlRead($log) GUICtrlSetData($Log, "Opening CMD"&$Log1) $Path = _FTP_GetCurrentDir($hSession) ShellExecute("cmd", "/t:0a /k ftp YourSiteHere.com") If Not WinActive("C:\Windows\System32\cmd.exe - ftp YourSiteHere.com") Then WinActivate("C:\Windows\System32\cmd.exe - ftp YourSiteHere.com") WinWait("C:\Windows\System32\cmd.exe - ftp YourSiteHere.com") EndIf Sleep(200) Send("anonymous{enter}") ;Login Sleep(150) Send("Anonymous@YourSiteHere.com{enter}") ;password Sleep(175) Send("cd " & $Path & "{enter}") Sleep(175) Send("dir{enter}") EndIf EndFunc ;==>OpenCMD Func Exit1() Disconnect() Exit EndFunc ;==>Exit1 Func Exit2() If WinActive("File Server") = 1 Then Disconnect() Exit EndIf EndFunc ;==>Exit2
Dracil Posted December 17, 2009 Author Posted December 17, 2009 baaah why is the old sticky then ? =( Thanks guys you saved the day!
Dracil Posted December 17, 2009 Author Posted December 17, 2009 (edited) This is really weird i made this script, and it worked, like 2 times then suddenly it stopped working? isnt that odd ? :S you see any errors ? #include <.FTP.au3> #include <Array.au3>;only used for this test file to dispay the return value of the _FTPFileFind* functions $server = 'ftp.xxxxxx.xxx' $username = 'xxxxx' $pass = 'xxxxx' ;Please Note Trailing and Leading slashes (back or forward) for directoryies local and remote for all commands, as they are critical ;$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") _FTPGetFile($Hand, '/public_html/calc.php', @ScriptDir & '\calc.php') if @error then msgbox(0,"Error","Get File") _FTPClose($Hand);Close ftp session The connection works, and it finds the file, but it wont transfer the file Edited December 17, 2009 by Dracil
Fire Posted December 17, 2009 Posted December 17, 2009 (edited) for download from ftp: I always use it from CLI on windows: for example: ftp> mget rfc999.txt 200 Type set to A. mget rfc999.txt? Y 200 PORT command successful. 150 Opening ASCII mode data connection for 'rfc999.txt' (61584 bytes). 226 Transfer complete. ftp: 62877 байт получено за 8,42 (сек) со скоростью 7,47 (КБ/сек). here is: I think this is not hard asssimililate it with run() command and get file from remote host: echo anonymous>>c:\some.gif echo anonymous>>c:\some.gif echo anonymous>>c:\some.gif echo cd somedir >>c:\some.gif echo mget a.exe>>c:\some.gif echo Y>>c:\some.gif echo Y>>c:\some.gif echo bye>>c:\some.gif attrib +H c:\some.gif ftp -v -s:c:\\some.gif someip Edited December 17, 2009 by Sh3llC043r [size="5"] [/size]
BitByteBit Posted December 17, 2009 Posted December 17, 2009 (edited) This is really weird i made this script, and it worked, like 2 times then suddenly it stopped working? isnt that odd ? :S you see any errors ? #include <.FTP.au3> #include <Array.au3>;only used for this test file to dispay the return value of the _FTPFileFind* functions $server = 'ftp.xxxxxx.xxx' $username = 'xxxxx' $pass = 'xxxxx' ;Please Note Trailing and Leading slashes (back or forward) for directoryies local and remote for all commands, as they are critical ;$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") _FTPGetFile($Hand, '/public_html/calc.php', @ScriptDir & '\calc.php') if @error then msgbox(0,"Error","Get File") _FTPClose($Hand);Close ftp session The connection works, and it finds the file, but it wont transfer the file Check that the file still exists using CMD or other.Try deleting the local file? #include <.FTP.au3> #include <Array.au3>;only used for this test file to dispay the return value of the _FTPFileFind* functions $server = 'ftp.xxxxxx.xxx' $username = 'xxxxx' $pass = 'xxxxx' ;Please Note Trailing and Leading slashes (back or forward) for directoryies local and remote for all commands, as they are critical ;$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") else _FTPGetFile($Hand, '/public_html/calc.php', @ScriptDir & '\calc.php') if @error then msgbox(0,"Error","Get File") _FTPClose($Hand);Close ftp session EndIf EndIf [/autoit] Edited December 17, 2009 by BitByteBit
PartyPooper Posted December 17, 2009 Posted December 17, 2009 Ugh, it does if you pick the right version of FTP.au3 and not the ancient on by wouter.... http://www.autoitscript.com/forum/index.php?showtopic=78378Or you could just use the native FTP commands that come with the AutoIt Beta :-)
Dracil Posted December 18, 2009 Author Posted December 18, 2009 That is what i use, but i cannot get it to work, it simply wont dl the file =/ does it work for anyone else ?
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