Sign in to follow this  
Followers 0
z3r0c00l12

_FTP_Close Problem

3 posts in this topic

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

Share this post


Link to post
Share on other sites



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)?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0