Après un peu de recherche sur la toile je n'ai pas trouvé la solution à mon problème.
Je me suis monté un serveur FTP FileZilla et j'utilise Autoit comme client FTP.
Je vais transférer des fichiers qui font entre 15 et 150Go, pour cette raison j'ai besoin d'avoir l'option de reprise de téléchargement si une coupure il y a.
Merci de votre aide
Voici mon bout code
► Afficher le texte
Code : Tout sélectionner
Opt("TrayIconHide", 1)
#Include "FTPEx2.au3"
#include <String.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $e_file, $BBrowse, $BOK, $INPlogin, $INPpwd, $f_add, $GUI_Upload, $WinConnection, $Filename, $SharePath, $WinUoD, $BUpload, $B_Upload
Global $GUI_Download, $B_Download, $BDownload, $f_save, $BFSF, $e_path, $FTP_Link, $Path_Save
;~ FTP Address ===============================================================================================================================
Global $server = 'FTP adress'
GUI_Upload()
GUI_Download()
Upload_or_Download()
Do
$msg = GUIGetMsg()
Switch $msg
Case $BBrowse
_BIN()
Case $BFSF
_SAVE()
Case $BUpload
GUISetState(@SW_HIDE, $WinUoD)
GUISetState(@SW_SHOW, $GUI_Upload)
Case $BDownload
GUISetState(@SW_HIDE, $WinUoD)
GUISetState(@SW_SHOW, $GUI_Download)
Case $B_Download
Check_Download()
Case $B_Upload
Check_Upload()
EndSwitch
Until $msg = $GUI_EVENT_CLOSE
Func Upload_or_Download()
$WinUoD = GUICreate("File Transfer Access", 490, 70)
GUICtrlCreateLabel("Do you want to Upload or Download?", 10, 10, 200, 20)
$BUpload = GUICtrlCreateButton("Upload", 30, 40, 200, 20)
$BDownload = GUICtrlCreateButton("Download", 260, 40, 200, 20)
GUISetState(@SW_SHOW, $WinUoD)
EndFunc
Func GUI_Upload()
$GUI_Upload = GUICreate("File Transfer UL", 230, 128)
$LBLlogin = GUICtrlCreateLabel("Login:", 47.5, 10, 50, 20)
$INPlogin = GUICtrlCreateInput("", 102.5, 8, 80, 20)
$LBLpwd = GUICtrlCreateLabel("Password:", 47.5, 40, 95, 20)
$INPpwd = GUICtrlCreateInput("", 102.5, 38, 80, 20, $ES_PASSWORD)
$e_file = GUICtrlCreateEdit('File name', 10, 68, 170, 20, 2176)
$BBrowse = GUICtrlCreateButton("...", 190, 68, 30, 20)
GUICtrlSetTip($BBrowse, 'Select a file to send')
$B_Upload = GUICtrlCreateButton("&Upload", 10, 98, 210, 20)
;~ GUISetState(@SW_SHOW, $GUI_Upload)
EndFunc
Func GUI_Download()
$GUI_Download = GUICreate("File Transfer DL", 275, 155)
GUICtrlCreateLabel("Put the FTP link to download the file:", 10, 10, 180, 20)
$FTP_Link = GUICtrlCreateInput("", 10, 35, 255, 20)
GUICtrlCreateLabel("Save to folder:", 10, 72, 180, 20)
$e_path = GUICtrlCreateEdit('Path', 10, 95, 215, 20, 2176)
$BFSF = GUICtrlCreateButton("...", 235, 95, 30, 20)
GUICtrlSetTip($BFSF, 'Select a file to save')
$B_Download = GUICtrlCreateButton("&Download", 10, 125, 255, 20)
EndFunc
Func GUI_Connecting()
$WinConnection = GUICreate("EquiPoise FTP Connection", 200, 40, -1, -1, $WS_POPUPWINDOW)
GUICtrlCreateLabel(" Connecting...", 10, 10, 180, 20)
GUISetState(@SW_SHOW, $WinConnection)
EndFunc
Func _BIN()
$f_add = FileOpenDialog('Select file to send', "", '(*.*)', 1 + 2, "")
If Not @error Then
$Filename = StringRegExpReplace($f_add, '^.*\\', "")
$Filename = StringRegExpReplace($Filename, " ", "_")
GUICtrlSetData($e_file, $Filename)
EndIf
EndFunc
Func _SAVE()
$f_save = FileSelectFolder('Select folder to save', "")
If Not @error Then
$Filename = StringRegExpReplace(GUICtrlRead($FTP_Link), '^.*/', "")
$Path_Save = StringReplace($f_save & "\" & $Filename, "\\", "\")
GUICtrlSetData($e_path, $Path_Save)
EndIf
EndFunc
Func CreatePath()
For $i = 0 to 7
If Random() < 0.5 Then
;Capitals
$Letter = Chr(Random(Asc("A"), Asc("Z"), 1))
$SharePath = $SharePath & $Letter
Else
;Lower case
$Letter = Chr(Random(Asc("a"), Asc("z"), 1))
$SharePath = $SharePath & $Letter
Endif
Next
EndFunc
Func Check_Upload()
If $f_add = "" Then
MsgBox(48, "Error", "You must select one file")
Else
If FileExists($f_add) Then
GUISetState(@SW_SHOW, $GUI_Upload)
Upload()
Else
MsgBox(48, "Error", "File not found")
EndIf
EndIf
EndFunc
Func Check_Download()
If GUICtrlRead($FTP_Link) = "" Then
MsgBox(48, "Error", "Put the FTP link to download the file")
Else
If $f_save = "" Then
MsgBox(48, "Error", "Select an folder to save your file")
Else
GUISetState(@SW_SHOW, $GUI_Download)
Download()
Exit
EndIf
EndIf
EndFunc
Func Upload()
GUISetState(@SW_HIDE, $GUI_Upload)
GUI_Connecting()
$Open = _FTP_Open('MyFTP Control')
$Conn = _FTP_Connect($Open, $server, GUICtrlRead($INPlogin), GUICtrlRead($INPpwd))
If $Conn <> 0x00CC0008 Then
GUISetState(@SW_HIDE, $WinConnection)
MsgBox(16, "Error connection", "Check your login or password" & @CRLF & @CRLF & "or" & @CRLF & @CRLF & "Check your internet connection ")
GUISetState(@SW_SHOW, $GUI_Upload)
Else
CreatePath()
$FileName = StringRegExpReplace($f_add, '^.*\\', "")
$ErrDir = _FTP_DirCreate($Conn, "/" & $SharePath)
If $ErrDir = 0 Then
MsgBox(16, "Error dir", "Create Folder failed")
Exit
EndIf
GUISetState(@SW_HIDE, $WinConnection)
$Filename = StringRegExpReplace($Filename, " ", "_")
Global $T_Start_Upload = _NowCalc()
$Upload = _FTP_ProgressUpload($Conn, $f_add, "/" & $SharePath & "/" & $Filename)
;~ ConsoleWrite(@error)
If @error Then
Switch @error
Case -3
MsgBox(16, "Error transfer: " & @error, "Create File failed")
Case -4
MsgBox(16, "Error transfer: " & @error, "file failed")
Case -5
MsgBox(16, "Error transfer: " & @error, "Close File failed")
Case -6
MsgBox(16, "Error transfer: " & @error, "Download aborted by Percentage Func and Return of Called Function")
EndSwitch
Exit
EndIf
$Ftpc = _FTP_Close($Open)
msgbox(0, "File uploaded", "ftp://" & $server & "/" & $SharePath & "/" & $FileName)
Exit
EndIf
EndFunc
Func Download()
GUISetState(@SW_HIDE, $GUI_Download)
GUI_Connecting()
$Open = _FTP_Open('MyFTP Control')
$Conn = _FTP_Connect($Open, $server, 'anonymous', '')
;~ ConsoleWrite($Conn)
If $Conn <> 0x00CC0008 Then
GUISetState(@SW_HIDE, $WinConnection)
MsgBox(16, "Error connection", "Check your login or password" & @CRLF & @CRLF & "or" & @CRLF & @CRLF & "Check your internet connection ")
Exit
EndIf
GUISetState(@SW_HIDE, $WinConnection)
$Path_Download= StringReplace(GUICtrlRead($FTP_Link), "ftp://" & $server, "")
$Upload = _FTP_ProgressDownload($Conn, $Path_Save, $Path_Download)
If @error Then
Switch @error
Case -1
MsgBox(16, "Error transfer: " & @error, "Local file couldn't be created")
Case -3
MsgBox(16, "Error transfer: " & @error, "Open RemoteFile failed")
Case -4
MsgBox(16, "Error transfer: " & @error, "Read from Remotefile failed")
Case -5
MsgBox(16, "Error transfer: " & @error, "Close RemoteFile failed")
Case -6
MsgBox(16, "Error transfer: " & @error, "Download aborted by PercentageFunc and Return of Called Function")
EndSwitch
Exit
EndIf
Exit
EndFunc

