z3r0c00l12 Posted March 27, 2011 Share Posted March 27, 2011 I have a script which downloads a file from an FTP server. In some cases the file is not there and the script itself is meant to handle that exception, but I noticed a problem. While everything works fine, this is not urgent, but when I do the _FTP_FileGet and the file is missing, _FTP_Close always fails to close the connection and returns 0. I had a look at the connections on my computer by doing a "netstat", and I can see the connection is still active, or rather is in CLOSE_WAIT and stays like that until I turn off my computer. #include <FTPEx.au3> $username="username" $password="password" $Open = _FTP_Open("myftp") If $Open <> 0 AND Ping("127.0.0.1") > 0 Then $Conn = _FTP_Connect($Open, "127.0.0.1", $username, $password) If $Conn <> 0 Then If _FTP_FileGet($Conn,"MissingFile.txt","C:\MissingFile.txt") <> 1 Then ConsoleWrite("_FTP_FileGet Error: " & @ERROR & " Extended: " & @EXTENDED & @CRLF) EndIf $Close = _FTP_Close($Open) ConsoleWrite("Close status: " & $Close & @CRLF) EndIf Link to comment Share on other sites More sharing options...
sahsanu Posted March 28, 2011 Share Posted March 28, 2011 I have a script which downloads a file from an FTP server. In some cases the file is not there and the script itself is meant to handle that exception, but I noticed a problem. While everything works fine, this is not urgent, but when I do the _FTP_FileGet and the file is missing, _FTP_Close always fails to close the connection and returns 0.Hello,I've tried it on my own ftp server and I've no problems with _FTP_Close function. It is working fine even if the file doesn't exist. Could you please put an @error on your last Consolewrite just to check what is the error code you are getting when close status is 0 (so we can figure out what is going on)? Link to comment Share on other sites More sharing options...
z3r0c00l12 Posted April 18, 2011 Author Share Posted April 18, 2011 I found the problem, when I took a further look at the code, I saw I had actually set the _FTP_Close in an if statement which caused _FTP_Close to be called only if the file was downloaded properly. I updated the code and it works perfectly now. 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