Sign in to follow this  
Followers 0
fusion400

Try to reconnect to ftp until file upload succeeds.

4 posts in this topic

Hello i have this code below that connects to an ftp server this works really well

but i want to make it bullet proof so it tries to reconnect and upload the files

until it recieves that the transfer was successfull how can this be done in an easy way?

The script should never stop trying to reconnect until it is completely successfull.

So even if the ftp server is temporarily down, overloaded by too many connections or

that the internet connection is not work it should still keep trying.

$FTP = _FTP_Open('NC FTP')
$hConnect = _FTP_Connect($FTP, $SERVER, $NAME, $PASS,1)
$Ftpd = _FTP_DirCreate($hConnect, $date)
$ftps = _FTP_DirSetCurrent($hConnect, $date)
$Ftpp = _FTP_FilePut($hConnect,$datornamn & "-1.jpg", $datornamn & "-1.jpg")
$Ftpp = _FTP_FilePut($hConnect,$datornamn & "-2.jpg", $datornamn & "-2.jpg")
$Ftpc = _FTP_Close($FTP)

Share this post


Link to post
Share on other sites



just a long shot here but maybe:

$FTP = _FTP_Open('NC FTP')
while 1
sleep(100)
$hConnect = _FTP_Connect($FTP, $SERVER, $NAME, $PASS,1)
if $hConnect <> @error then exitloop
wend
$Ftpd = _FTP_DirCreate($hConnect, $date)
$ftps = _FTP_DirSetCurrent($hConnect, $date)
$Ftpp = _FTP_FilePut($hConnect,$datornamn & "-1.jpg", $datornamn & "-1.jpg")
$Ftpp = _FTP_FilePut($hConnect,$datornamn & "-2.jpg", $datornamn & "-2.jpg")
$Ftpc = _FTP_Close($FTP)

Share this post


Link to post
Share on other sites

I'd do something line this: Could do with some user feedback though.

I'm not sure how to test the status of the current _FTP_Connect and you might need to make sure it's disconnected before attempting to reconnect.

Perhaps someone else has an idea for that.

#include <FTPEx.au3>
Local $hFTP, $hConnect

Local $bFTPd, $bFTPp

Local $sServer = ""
Local $sName = ""
Local $sPass = ""
Local $sDate = ""
Local $sDatornNamn = ""

$hFTP = _FTP_Open('NC FTP')
While 1
    Sleep(500)
    $hConnect = _FTP_Connect($hFTP, $sServer, $sName, $sPass,1)
    If @error Then ContinueLoop
    If Not $bFTPd Then $bFTPd = _FTP_DirCreate($hConnect, $sDate)
    If Not $bFTPd Then ContinueLoop
    If Not $bFTPp Then $bFTPp = _FTP_FilePut($hConnect,$sDatornNamn & "-1.jpg", $sDatornNamn & "-1.jpg")
    If Not $bFTPp Then ContinueLoop
    _FTP_FilePut($hConnect,$sDatornNamn & "-2.jpg", $sDatornNamn & "-2.jpg")
    If @error Then
        ContinueLoop
    Else
        ExitLoop
    EndIf
WEnd
_FTP_Close($hFTP)

Share this post


Link to post
Share on other sites

I'd do something line this: Could do with some user feedback though.

I'm not sure how to test the status of the current _FTP_Connect and you might need to make sure it's disconnected before attempting to reconnect.

Perhaps someone else has an idea for that.

#include <FTPEx.au3>
Local $hFTP, $hConnect

Local $bFTPd, $bFTPp

Local $sServer = ""
Local $sName = ""
Local $sPass = ""
Local $sDate = ""
Local $sDatornNamn = ""

$hFTP = _FTP_Open('NC FTP')
While 1
    Sleep(500)
    $hConnect = _FTP_Connect($hFTP, $sServer, $sName, $sPass,1)
    If @error Then ContinueLoop
    If Not $bFTPd Then $bFTPd = _FTP_DirCreate($hConnect, $sDate)
    If Not $bFTPd Then ContinueLoop
    If Not $bFTPp Then $bFTPp = _FTP_FilePut($hConnect,$sDatornNamn & "-1.jpg", $sDatornNamn & "-1.jpg")
    If Not $bFTPp Then ContinueLoop
    _FTP_FilePut($hConnect,$sDatornNamn & "-2.jpg", $sDatornNamn & "-2.jpg")
    If @error Then
        ContinueLoop
    Else
        ExitLoop
    EndIf
WEnd
_FTP_Close($hFTP)

Thanks alot for all the help

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