+ // Set transfermode back to the original. Only the "SIZE"-command
+ // is dependant on transfermode
+ if ( oldTransfermode != NONE )
+ {
+ SetTransferMode(oldTransfermode);
+ }
+
+ // this is not a direct else clause.. The size command might return an
+ // invalid "2yz" reply
+ if ( !ok )
+ {
+ // The server didn't understand the "SIZE"-command or it
+ // returned an invalid reply.
+ // We now try to get details for the file with a "LIST"-command
+ // and then parse the output from there..
+ wxArrayString fileList;
+ if ( GetList(fileList, fileName, true) )
+ {
+ if ( !fileList.IsEmpty() )
+ {
+ // We _should_ only get one line in return, but just to be
+ // safe we run through the line(s) returned and look for a
+ // substring containing the name we are looking for. We
+ // stop the iteration at the first occurrence of the
+ // filename. The search is not case-sensitive.
+ const size_t numFiles = fileList.size();
+ size_t i;
+ for ( i = 0; i < fileList.GetCount(); i++ )
+ {
+ if ( fileList[i].Upper().Contains(fileName.Upper()) )
+ break;
+ }
+
+ if ( i != numFiles )
+ {
+ // The index i points to the first occurrence of
+ // fileName in the array Now we have to find out what
+ // format the LIST has returned. There are two
+ // "schools": Unix-like
+ //
+ // '-rw-rw-rw- owner group size month day time filename'
+ //
+ // or Windows-like
+ //
+ // 'date size filename'
+
+ // check if the first character is '-'. This would
+ // indicate Unix-style (this also limits this function
+ // to searching for files, not directories)
+ if ( fileList[i].Mid(0, 1) == wxT("-") )
+ {
+
+ if ( wxSscanf(fileList[i].c_str(),
+ wxT("%*s %*s %*s %*s %i %*s %*s %*s %*s"),
+ &filesize) != 9 )
+ {
+ // Hmm... Invalid response
+ wxLogDebug(wxT("Invalid LIST response"));
+ }
+ }
+ else // Windows-style response (?)
+ {
+ if ( wxSscanf(fileList[i].c_str(),
+ wxT("%*s %*s %i %*s"),
+ &filesize) != 4 )
+ {
+ // something bad happened..?
+ wxLogDebug(wxT("Invalid or unknown LIST response"));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // filesize might still be -1 when exiting
+ return filesize;