@@ -1105,6 +1105,12 @@ function _nlist_helper($dir, $recursive, $relativeDir)
11051105 {
11061106 $ files = $ this ->_list ($ dir , false );
11071107
1108+ // If we get an int back, then that is an "unexpected" status.
1109+ // We do not have a file list, so return false.
1110+ if (is_int ($ files )) {
1111+ return false ;
1112+ }
1113+
11081114 if (!$ recursive || $ files === false ) {
11091115 return $ files ;
11101116 }
@@ -1140,6 +1146,13 @@ function _nlist_helper($dir, $recursive, $relativeDir)
11401146 function rawlist ($ dir = '. ' , $ recursive = false )
11411147 {
11421148 $ files = $ this ->_list ($ dir , true );
1149+
1150+ // If we get an int back, then that is an "unexpected" status.
1151+ // We do not have a file list, so return false.
1152+ if (is_int ($ files )) {
1153+ return false ;
1154+ }
1155+
11431156 if (!$ recursive || $ files === false ) {
11441157 return $ files ;
11451158 }
@@ -1207,8 +1220,12 @@ function _list($dir, $raw = true)
12071220 break ;
12081221 case NET_SFTP_STATUS :
12091222 // presumably SSH_FX_NO_SUCH_FILE or SSH_FX_PERMISSION_DENIED
1210- $ this ->_logError ($ response );
1211- return false ;
1223+ if (strlen ($ response ) < 4 ) {
1224+ return false ;
1225+ }
1226+ extract (unpack ('Nstatus ' , $ this ->_string_shift ($ response , 4 )));
1227+ $ this ->_logError ($ response , $ status );
1228+ return $ status ;
12121229 default :
12131230 user_error ('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS ' );
12141231 return false ;
@@ -1277,7 +1294,7 @@ function _list($dir, $raw = true)
12771294 extract (unpack ('Nstatus ' , $ this ->_string_shift ($ response , 4 )));
12781295 if ($ status != NET_SFTP_STATUS_EOF ) {
12791296 $ this ->_logError ($ response , $ status );
1280- return false ;
1297+ return $ status ;
12811298 }
12821299 break 2 ;
12831300 default :
@@ -1953,7 +1970,7 @@ function _setstat_recursive($path, $attr, &$i)
19531970 $ i = 0 ;
19541971 $ entries = $ this ->_list ($ path , true );
19551972
1956- if ($ entries === false ) {
1973+ if ($ entries === false || is_int ( $ entries ) ) {
19571974 return $ this ->_setstat ($ path , $ attr , false );
19581975 }
19591976
@@ -2798,9 +2815,14 @@ function _delete_recursive($path, &$i)
27982815 $ i = 0 ;
27992816 $ entries = $ this ->_list ($ path , true );
28002817
2801- // normally $entries would have at least . and .. but it might not if the directories
2802- // permissions didn't allow reading
2803- if (empty ($ entries )) {
2818+ // The folder does not exist at all, so we cannot delete it.
2819+ if ($ entries === NET_SFTP_STATUS_NO_SUCH_FILE ) {
2820+ return false ;
2821+ }
2822+
2823+ // Normally $entries would have at least . and .. but it might not if the directories
2824+ // permissions didn't allow reading. If this happens then default to an empty list of files.
2825+ if ($ entries === false || is_int ($ entries )) {
28042826 $ entries = array ();
28052827 }
28062828
0 commit comments