bggashnik Posted January 9, 2008 Posted January 9, 2008 Ok.I read about FTP.au3 and I decided to use it so I can upload one text file on my FTP server.Some people said that it works and I also thin so but the problem is that isn't very well explained.Well, here's now my code: #include <FTP.au3> $server = "ftp.byethost13.com" $username = "b13_1427267" $pass = "this is my password" $Open = _FTPOpen("ftp.byethost13.com")[color="#008000"][b];I'm not sure what to write here[/b][/color] $Conn = _FTPConnect($Open, $server, $username, $pass) $Ftpp = _FtpPutFile($Conn, "blabla.txt", "/htdocs/upload/blabla.txt") $Ftpc = _FTPClose($Open) The file I wanna upload is blabla.txt and I wanna upload it in /htdocs/upload folder.I changed the permissions of this folder so I can upload this file.Could you help me, please!
rbhkamal Posted January 9, 2008 Posted January 9, 2008 (edited) Ok.I read about FTP.au3 and I decided to use it so I can upload one text file on my FTP server.Some people said that it works and I also thin so but the problem is that isn't very well explained.Well, here's now my code: #include <FTP.au3> $server = "ftp.byethost13.com" $username = "b13_1427267" $pass = "this is my password" $Open = _FTPOpen("ftp.byethost13.com")[color="#008000"][b];I'm not sure what to write here[/b][/color] $Conn = _FTPConnect($Open, $server, $username, $pass) $Ftpp = _FtpPutFile($Conn, "blabla.txt", "/htdocs/upload/blabla.txt") $Ftpc = _FTPClose($Open) The file I wanna upload is blabla.txt and I wanna upload it in /htdocs/upload folder.I changed the permissions of this folder so I can upload this file.Could you help me, please! You have to open the dll wininet.dll before you can use any FTP functions.... I don't know why but it doesn't work without it. #include <FTP.au3> $__ftp_hWinInetDll = DllOpen( 'wininet.dll' ) If $__ftp_hWinInetDll == -1 Then ConsoleWrite( "-- ERROR FROM FTP.au3: Unable to open WinInet.dll" & @LF ) $__ftp_hWinInetDll = 'wininet.dll' EndIf $server = "ftp.byethost13.com" $username = "b13_1427267" $pass = "this is my password" $Open = _FTPOpen("ftp.byethost13.com") $Conn = _FTPConnect($Open, $server, $username, $pass) $Ftpp = _FtpPutFile($Conn, "blabla.txt", "/htdocs/upload/blabla.txt") $Ftpc = _FTPClose($Open) Edit: also don't forget to put some error checking after _FTPOpen and _FTPConnect Edited January 9, 2008 by rbhkamal "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix
bggashnik Posted January 9, 2008 Author Posted January 9, 2008 Well, it doesn't work.Could you tell me what is $Open for and probably how can i make it work?
rbhkamal Posted January 9, 2008 Posted January 9, 2008 (edited) _FTPOpen is an initialization function just like tcpstartup() and udpstartup(), in that function you can set some flags check MSDN you just use the defaults._FTPConnect is the function that establish the actual connection to the FTP server.Follow these steps:1- Disable windows firewall2- make sure that your FTP.au3 looks like the one I attached3- Run the script below after you fill in the blanks:#include <FTP.au3> $server = "BLANK" $username = "BLANK" $pass = "BLANK" $Open = _FTPOpen("anything") consolewrite( "Open: " & $Open & @crlf ) $Conn = _FTPConnect($Open, $server, $username, $pass) consolewrite( "Connect: " & $Conn & @crlf ) $Ftpp = _FtpPutFile($Conn, @ScriptDir&"\test.txt", "/home/test.txt") consolewrite( "Put Result: " & $Ftpp & @crlf ) $Ftpc = _FTPClose($Open)FTP.au3Edit: I verified that the script below works just fine Edited January 9, 2008 by rbhkamal "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix
bggashnik Posted January 10, 2008 Author Posted January 10, 2008 O.K.Thanks.I see it's uploading now but the script runs forever and when i decided to stop it the text file,uploaded in the server was empty.When the script finishes the upload?
bggashnik Posted January 10, 2008 Author Posted January 10, 2008 I test it one more time and the program uploaded it on the ftp server and finished its job but the file,uploaded on the server is empty.
rbhkamal Posted January 10, 2008 Posted January 10, 2008 (edited) can you help me please?What is the return value of _FTPFilePut()? This sounds like the files on the local file on the machine wasn't found or the DATA connection failed to establish (probably a firewall blocking it), so the FTP server closed the file without writing anything to it. thus the empty file. I'm sure the problem is not from FTP.au3 anymore, instead it just a flag or something similar. Make sure that the file you are trying to transfer exists on the local machine before you transfer it. Then you should find out if the server uses passive or active ftp data connections and make sure that your firewall does not block it. Here, use this script: expandcollapse popup#include <FTP.au3> $server = "" $username = "" $pass = "" $sLocalFile = @ScriptDir&"\test.txt" $sRemoteFile = "/home/test.txt" ;Local Const $INTERNET_FLAG_PASSIVE = 0x08000000 ;Local Const $INTERNET_FLAG_TRANSFER_ASCII = 0x00000001 ;Local Const $INTERNET_FLAG_TRANSFER_BINARY = 0x00000002 Local Const $WININET_API_FLAG_SYNC = 0x00000004 If Not FileExists( $sLocalFile ) Then MsgBox( 16 , "ERROR" , "File doesn't exist!" ) Exit EndIf $Open = _FTPOpen("anything") If @error Or Not $Open Then ConsoleWrite( "Error(" & @error & ") > Unable to initialize FTP.au3" & @LF ) Exit EndIf $Conn = _FTPConnect($Open, $server, $username, $pass );$INTERNET_FLAG_PASSIVE If @error Or Not $Conn Then ConsoleWrite( "Error(" & @error & ") > Unable to establish the connection to "&$server & @LF ) Exit EndIf $Ftpp = _FtpPutFile($Conn, $sLocalFile , $sRemoteFile );$WININET_API_FLAG_SYNC If $Ftpp == 1 Then ConsoleWrite( "Transfer successful!" & @LF ) Exit EndIf $Ftpc = _FTPClose($Open) Edit: Try the $INTERNET_FLAG_PASSIVE flag after you're sure that the file exists on the local machine Regards, RK Edited January 10, 2008 by rbhkamal "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix
rbhkamal Posted January 10, 2008 Posted January 10, 2008 (edited) VERY BIG NOTEIt looks like the _FTPFilePut() transfers the file in the background so you have to wait.... give it time to finish uploading. OR just set the ASYNC flag Global Const $WININET_API_FLAG_ASYNC = 0x00000001 // force async operationoÝ÷ Øò¢ìÛh¶¶§±÷«ém^~)^²)íæÚrH+¢éݺǫ¶¬Êw!®èºÇåj®¶sdvÆö&Â6öç7Bb33cµtääUEôôdÄuõ5ä2ÒBòòf÷&6R7æ2÷W&Fö Edited January 10, 2008 by rbhkamal "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix
ikaros Posted July 21, 2010 Posted July 21, 2010 Hi guys, Great UDF, working with it alot... However, how can i change permissions to a specific file? Can you send me an example? Thanks Ofer,WWW Home baseArticles for allOnline statistics toolThe online mass mailerWorld of bicycles
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