I have a file on my home ftp server call FileOnFTPserver.txt
I want to download this file from another computer and read line 1. If line 1 is 1 then continue, if it is not 1 then keep downloading and reading it until line 1 does equal to 1
First I tried it with FTP Functions by Olfen & Andreone found here, http://www.autohotke...pic.php?t=10393
I am able to download it just fine, I read line 1 and it does not equal 1 (it equals 0) so I keep looping and downloading FileOnFTPserver.txt
Here is the problem.
When, I change line 1 on FileOnFTPserver.txt at my server and the loop downloads it again it never downloads the changed text file. I know it is downloading it again because while my script was looping and downloading it I deleted Status.txt and it was downloaded again. But always with 0 as the first line.
Here is the script.
#Include C:\Program Files\AutoHotkey\lib\ftp.ahk
SetWorkingDir, %A_ScriptDir%
Username = JohnDoe
Password = ahk
FTPserver = 111.111.111.111
FtpConnection := FtpOpen(FTPserver, "21", Username, Password)
If (FtpConnection != 1)
{
MsgBox,16,Error 1, Not able to upload File.`nMake sure you are connected to the internet and try again.
Return
}
RemoteFile = FileOnFTPServer.txt
NewFile = Status.txt
KeepChecking:
FtpGetFile( RemoteFile, NewFile)
FileReadLine,Status,Status.txt,1 ;I go to my FTP server and change FileOnFTPServer.txt line 1 to 1 - It never downloads the changed text file. I even deleted the Status.txt file and it downloaded the unchanged txt file.
if Status <> 1
{
sleep 1000
Goto KeepChecking
}
MsgBox finished
FileDelete,Status.txt
FtpClose()Since I am using Autohotkey_L, I rewrote the script using shajuls modified version for ahk_L, found here http://www.autohotke...getfile#p371957
This script won't even download the file. It logs into my server but my server gives an error "Cannot open data connection"
The script times out and downloads a blank Status.txt
I think the issue is with hConnect. I do not know what that is. I looked on MSDN and it says " Handle to an FTP session " so I thought maybe it was FtpConnection.
Here is that script
#Include C:\Program Files\AutoHotkey\lib\ftp.ahk
SetWorkingDir, %A_ScriptDir%
Username = JohnDoe
Password = ahk
FTPserver = 111.111.111.111
FtpConnection := Ftp_Open(FTPserver, "21", Username, Password)
If (FtpConnection = 0)
{
MsgBox,16,Error, Not able to upload File.`nMake sure you are connected to the internet and try again.
Return
}
RemoteFile = FileOnFTPServer.txt
NewFile = Status.txt
;FTP_GetFile(hConnect,RemoteFile, NewFile="", Flags=0
KeepChecking: ;What is hConnect - I looked on MSDN and it says " Handle to an FTP session " so I thought maybe it was FtpConnection
Ftp_GetFile( FtpConnection,RemoteFile, NewFile)
FileReadLine,Status,Status.txt,1
if Status <> 1
{
sleep 1000
Goto KeepChecking
}
MsgBox done
FileDelete,Done.txt
Ftp_Close()Also, this taken from ftp.ahk by shajul.
FTP_GetFile(hConnect,RemoteFile, NewFile="", Flags=0) {
;Flags:
;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY)
;FTP_TRANSFER_TYPE_ASCII = 1
;FTP_TRANSFER_TYPE_BINARY = 2
If NewFile=
NewFile := RemoteFile
;global ic_hInternet
r := DllCall("wininet\FtpGetFile" , "uint", hConnect , "str", RemoteFile , "str", NewFile
, "int", 1 ;do not overwrite existing files
, "uint", 0 ;dwFlagsAndAttributes
, "uint", Flags
, "uint", 0) ;dwContext
Return (ErrorLevel or !r) ? 0 : 1
}Does 1 mean "do not overwrite existing files"I changed it to 0 and still have the same problem.
I suppose I need to get the script working using the ftp functions by shajul and then see if I have that same issue with it not downloading the changed FileOnFTPServer.txt




