Jump to content

_FTP_DirPutContents doesn't return any errors


ohos
 Share

Recommended Posts

Hi, i wrote simple ftp script to upload folder to list of ftp servers, but function _FTP_DirPutContents doesn't return errors in any case, even when i disconnect from intenet manually during uploading

here is my script

;123
#include <FTPEx.au3>
#include <Array.au3>
#include <File.au3>
#include<Date.au3>
;$curdate = @MON & "." & @MDAY & "." & @YEAR
$curdate = stringreplace(_NowDate()&' '&_NowTime(),':','-')

$server = ''
$username = ''
$pass = ''

$inifile = 'ftp_script.ini'

$aRetArray = 0


if not _FileReadToArray($inifile, $aRetArray,1,";") Then
    MsgBox(4096, "Ошибка[1]", "Не удалось прочитать файл настроек в массив "&$inifile&', ошибка '&@error)
    Exit
endif

;MsgBox(4096, "тест", $aRetArray[0][0])

;_ArrayDisplay($aRetArray, "settings show", Default);

if $aRetArray[0][0] < 1 Then
   MsgBox(4096, "Ошибка", "не правильное кол-во считанных строк настроек")
    Exit
 EndIf

;$aRetArray IP;login;pass;sourcedir;targetdir
for $i = 1 to $aRetArray[0][0]
   ;MsgBox(4096, "тест", 'внутри цикла')

   ;игнорирование закомеченных строк начинающихся с ;
   if StringCompare(StringLeft($aRetArray[$i][0],2),"//") = 0 Then
      ;MsgBox(4096, "тест", "пропущена строка настроек "&$i)
      ContinueLoop
   endif
   ;проверка все ли параметры указаны
   for $i2 = 0 to 4
      if StringCompare($aRetArray[$i][$i2],"") = 0 Then
         MsgBox(4096, "Ошибка", "пустой параметр "&$aRetArray[$i][$i2]&" № "&$i2&" в строке настроек № "&$i)
         Exit
      endif
   Next

   ;получение списка файлов из настроек
   $FileList = _FileListToArray($aRetArray[$i][3], '*', 1)
   if not IsArray($FileList) then
      MsgBox(4096, "Ошибка", 'В sourcedir нет файлов для копирования, строка № '&$i)
      exit
   endif

   $server = $aRetArray[$i][0]
   $username = $aRetArray[$i][1]
   $pass = $aRetArray[$i][2]
   ;коннект по фтп к серверу
   $Open = _FTP_Open('MyFTP Control')
   if $Open = 0 Then
      MsgBox(4096, "Ошибка", 'В $Open = _FTP_Open(MyFTP Control) строка № '&$i)
      exit
   EndIf
   $Conn = _FTP_Connect($Open, $server, $username, $pass,1)
   if $Conn = 0 Then
      MsgBox(4096, "Ошибка "&@ERROR, 'В $Conn = _FTP_Connect($Open, $server, $username, $pass,1) строка № '&$i&" serv "&$server&" username "&$username&" pass "&$pass)
      exit
   EndIf

   ;$serverdirs = stringsplit($aRetArray[$i][4],"/")
   ;MsgBox(4096, "тест", UBound($serverdirs))
   ;


   $remote_dir_list = _FTP_ListToArray($Conn,1)
   if $remote_dir_list[0] = 0 Then
      MsgBox(4096, "Ошибка", 'В _FTP_ListToArray строка № '&$i)
      exit
   endif

   ;_ArrayDisplay($remote_dir_list, "target dirs", Default);

    if UBound($remote_dir_list) > 0 Then
        for $n = 1 to UBound($remote_dir_list)-1
            if _FTP_DirPutContents($Conn,$aRetArray[$i][3],$remote_dir_list[$n]&"/"&$aRetArray[$i][4],1) = 0 Then
               MsgBox(4096, "Ошибка", 'В _FTP_DirPutContents строка № '&$i)
            endif
        next
    EndIf

    $Ftpc = _FTP_Close($Open)
next

MsgBox(4096, "Завершено успешно!", 'Завершено успешно!')

exit

so at

if _FTP_DirPutContents($Conn,$aRetArray[$i][3],$remote_dir_list[$n]&"/"&$aRetArray[$i][4],1) = 0 Then
   MsgBox(4096, "Ошибка", 'В _FTP_DirPutContents строка № '&$i)
endif

no errors happen when i disconnect internet, but why the hell? :D

to work this script need a file called ftp_script.ini near executable and this file should contain a line like

IP;login;password;source_folder_name;sub_folder1/sub_folder2

(source_folder_name must be near executable as well)

Script will check all remote folders from "home folder" on ftp and try enter them like

each_remote_folder+/+sub_folder1/sub_folder2

Link to comment
Share on other sites

Seems i found why, because _FTP_DirPutContents implementation just call _FTP_FilePut without checking the result

Func _FTP_DirPutContents($l_InternetSession, $s_LocalFolder, $s_RemoteFolder, $b_RecursivePut, $iContext = 0)
    If StringRight($s_LocalFolder, 1) == "\" Then $s_LocalFolder = StringTrimRight($s_LocalFolder, 1)
    ; Shows the filenames of all files in the current directory.
    Local $hSearch = FileFindFirstFile($s_LocalFolder & "\*.*")

    ; Check if the search was successful
    If $hSearch = -1 Then Return SetError(1, 0, 0)

    Local $sFile
    While 1
        $sFile = FileFindNextFile($hSearch)
        If @error Then ExitLoop
        If StringInStr(FileGetAttrib($s_LocalFolder & "\" & $sFile), "D") Then
            _FTP_DirCreate($l_InternetSession, $s_RemoteFolder & "/" & $sFile)
            If $b_RecursivePut Then
                _FTP_DirPutContents($l_InternetSession, $s_LocalFolder & "\" & $sFile, $s_RemoteFolder & "/" & $sFile, $b_RecursivePut, $iContext)
            EndIf
        Else
            _FTP_FilePut($l_InternetSession, $s_LocalFolder & "\" & $sFile, $s_RemoteFolder & "/" & $sFile, 0, $iContext)
        EndIf
    WEnd

    ; Close the search handle
    FileClose($hSearch)
    Return 1
EndFunc   ;==>_FTP_DirPutContents
Link to comment
Share on other sites

  • 2 years later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...