Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormatException: Invalid radix-10 number (at character 4) #26

Closed
Al4AMD opened this issue May 18, 2024 · 6 comments
Closed

FormatException: Invalid radix-10 number (at character 4) #26

Al4AMD opened this issue May 18, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@Al4AMD
Copy link

Al4AMD commented May 18, 2024

Hi. i am using your package and in the 0.5.2 version, everything was okay but in new update, the downloadStream has a bug, or maybe my code has an error but i can't get anything out of it.
This is my code:

Future<void> establishConnectionPure() async {
  try {
    FtpClient client2 = FtpClient(
        socketInitOptions: FtpSocketInitOptions(
            host: widget.ipAddress,
            port: 21,
            timeout: const Duration(seconds: 30),
            transferType: FtpTransferType.binary),
        authOptions:
            const FtpAuthOptions(username: "ftp", password: "123456"),
        logCallback: ((value) {
          print("Value:\n" + value);
          if (value.toString().contains("permission denied") ||
              value.toString().contains("Illegal Reply Exception")) {
            final snackbar = CustomSnackBar(
              mainAlignment: MainAxisAlignment.end,
              crossAlignment: CrossAxisAlignment.center,
              showCloseIcon: true,
              duration: const Duration(milliseconds: 2000),
              backgroundColor: Colors.red,
              widgets: [
                ReusableText(
                    text: "server error",
                    style: appstyle(16, Colors.white, FontWeight.w500))
              ],
            );
            ScaffoldMessenger.of(context).showSnackBar(snackbar);
            Future.delayed(
                const Duration(milliseconds: 2000), () => Get.back());
          }
          if (value.toString().contains("rw") ||
              value.toString().contains("drw") ||
              value.toString().contains("wxr") ||
              value.toString().contains("xr") ||
              value.toString().contains("-x") ||
              value.toString().startsWith("dr")) {
            List<String> lines = value.split("\n");
            // lines.removeWhere((element) => element.isEmpty);
            setState(() {
              typeList.clear();
              nameList.clear();
              sizeList.clear();
              modifyList.clear();
            });
            for (String log in lines) {
              List<String> logParts = log.split(RegExp(r'\s+'));
              if (logParts.length > 9) {
                typeList.add(logParts[0]);
                sizeList.add(int.parse(logParts[4]));
                modifyList
                    .add('${logParts[5]} ${logParts[6]} ${logParts[7]}');
                nameList.add(logParts[8]);
              }
            }
          }
          print("$nameList\n$typeList\n$sizeList\n$modifyList");
          try {
            if (value.toString().contains("226") ||
                value.toString().contains("150")) {
              setState(() {
                _isGettingFtp = 0;
              });
            }
            if (value == "Connected to ${widget.ipAddress}:21") {
              setState(() {
                _ipVerified = 1;
              });
            }
          } catch (e) {
            final snackbar = CustomSnackBar(
              mainAlignment: MainAxisAlignment.center,
              crossAlignment: CrossAxisAlignment.center,
              backgroundColor: Colors.red,
              duration: const Duration(milliseconds: 2500),
              showCloseIcon: true,
              widgets: [
                ReusableText(
                    text: "error getting ip -> $e",
                    style: appstyle(16, Colors.white, FontWeight.w500))
              ],
            );
            ScaffoldMessenger.of(context).showSnackBar(snackbar);
          }
          try {
            if (value == "Logged in") {
              setState(() {
                _connectionEstablish = 1;
              });
            }
          } catch (e) {
            final snackbar = CustomSnackBar(
              mainAlignment: MainAxisAlignment.center,
              crossAlignment: CrossAxisAlignment.center,
              backgroundColor: Colors.red,
              duration: const Duration(milliseconds: 2500),
              showCloseIcon: true,
              widgets: [
                ReusableText(
                    text: "error getting user -> $e",
                    style: appstyle(16, Colors.white, FontWeight.w500))
              ],
            );
            ScaffoldMessenger.of(context).showSnackBar(snackbar);
          }
          try {
            if (value.toString().contains("257")) {
              setState(() {
                _filesRecieved = 1;
              });
            }
          } catch (e) {
            final snackbar = CustomSnackBar(
              mainAlignment: MainAxisAlignment.center,
              crossAlignment: CrossAxisAlignment.center,
              backgroundColor: Colors.red,
              duration: const Duration(milliseconds: 2500),
              showCloseIcon: true,
              widgets: [
                ReusableText(
                    text: "error getting file -> $e",
                    style: appstyle(16, Colors.white, FontWeight.w500))
              ],
            );
            ScaffoldMessenger.of(context).showSnackBar(snackbar);
          }
        }));
    setState(() {
      client = client2;
    });
  } catch (e) {
    final snackbar = CustomSnackBar(
      mainAlignment: MainAxisAlignment.end,
      crossAlignment: CrossAxisAlignment.center,
      showCloseIcon: true,
      duration: const Duration(milliseconds: 2000),
      backgroundColor: Colors.red,
      widgets: [
        ReusableText(
            text: "server error:\n$e",
            style: appstyle(16, Colors.white, FontWeight.w500))
      ],
    );
    ScaffoldMessenger.of(context).showSnackBar(snackbar);
    Future.delayed(const Duration(milliseconds: 2000), () => Get.back());
  }
  await client!.connect();
  print("\n\n");
  await client!.fs.listDirectory();
  setState(() {
    _connectionOverlay = 0;
  });
}

Future<bool> getPermissions() async {
  var status = await Permission.storage.status;
  if (!status.isGranted) {
    status = await Permission.storage.request();
  }
  return status.isGranted;
}

Future<List<int>> downloadStream(
  FtpClient client,
  FtpFile file, {
  int restSize = 0,
  OnTransferProgress? onReceiveProgress,
}) async {
  print("Downloading file with name: " + file.name);
  print("Downloading file with path: " + file.path);
  final result = <int>[];
  await client.fs
      .downloadFileStream(
        file,
        restSize: restSize,
        onReceiveProgress: onReceiveProgress,
      )
      .listen(result.addAll)
      .asFuture();
  return result;
}

Future<void> downloadFile(FtpClient client, FtpFile file,
    {OnTransferProgress? onReceiveProgress}) async {
  var result = <int>[];
  print("Hi from downloader\nname: ${file.name}\npath: ${file.path}");
  result = await downloadStream(client, file);
  print("Downlaod Stream got.");
  bool per = await getPermissions();
  if (per) {
    String? dir = await getFolderPath();
    if (dir != null) {
      final filePath = '$dir/${file.name}';
      final fileToSave = File(filePath);
      await fileToSave.writeAsBytes(result).then((value) {
        print("file saved");
        final snackbar = CustomSnackBar(
          mainAlignment: MainAxisAlignment.center,
          crossAlignment: CrossAxisAlignment.end,
          showCloseIcon: true,
          backgroundColor: Colors.blue,
          height: hieght * 0.025,
          duration: const Duration(milliseconds: 2000),
          widgets: [
            ReusableText(
                text: "download completed ...",
                style: appstyle(16, Colors.white, FontWeight.w600))
          ],
        );
        ScaffoldMessenger.of(context).showSnackBar(snackbar);
      });
    }
  }
}

FtpFile getFile(String path, FtpClient client) {
  print("String path: " + path);
  var file = FtpFile(
    path: path,
    client: client,
  );
  if (!file.isAbsolute) {
    file = client.fs.currentDirectory.getChildFile(path);
  }
  print("File got succesfully " + file.name);
  print("File got succesfully " + file.path);
  return file;
}

my scenario is to parse this callback log into lists inorder to build a better graphical interface.
"drwxr-xr-x 2 0 0 32768 May 15 2024 full_logs\r\n
drwxr-xr-x 2 0 0 32768 May 14 2024 audio\r\n
drwxr-xr-x 2 0 0 32768 May 13 2024 buffered\r\n
drwxr-xr-x 2 0 0 32768 May 12 2024 config\r\n
-rw-rw-rw- 2 0 0 32768 May 11 2024 shahed.dat\r\n
-rwxr-xr-x 2 0 0 32768 May 10 2024 ENC.opus\r\n"

i will split each part into its own list. but when i want to download the file, i get this error:

E/flutter (32191): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FormatException: Invalid radix-10 number (at character 5)
E/flutter (32191): 7202024
E/flutter (32191): ^
E/flutter (32191):
E/flutter (32191): #0 int._handleFormatError (dart:core-patch/integers_patch.dart:127:5)
E/flutter (32191): #1 int._parseRadix (dart:core-patch/integers_patch.dart:171:16)
E/flutter (32191): #2 int._parse (dart:core-patch/integers_patch.dart:99:12)
E/flutter (32191): #3 int.parse (dart:core-patch/integers_patch.dart:61:12)
E/flutter (32191): #4 FtpFile.size (package:pure_ftp/src/file_system/entries/ftp_file.dart:82:16)
E/flutter (32191):
E/flutter (32191): #5 FtpTransfer.downloadFileStream. (package:pure_ftp/src/file_system/ftp_transfer.dart:30:28)
E/flutter (32191):

and then timeout error.

but it was fine in previous versions

@crifurch
Copy link
Owner

I will fix it later, thanks

@Al4AMD
Copy link
Author

Al4AMD commented May 18, 2024

I will fix it later, thanks

Plz fix it ASAP
my project depends on you 😭😭

@crifurch
Copy link
Owner

It will be in few hours

@crifurch crifurch added the bug Something isn't working label May 18, 2024
@Al4AMD
Copy link
Author

Al4AMD commented May 18, 2024

It will be in few hours

Thanks a lot

crifurch added a commit that referenced this issue May 19, 2024
@crifurch
Copy link
Owner

@Al4AMD check 0.7.4

@Al4AMD
Copy link
Author

Al4AMD commented May 19, 2024

@Al4AMD check 0.7.4

Thanks a lot.
Wish you the best

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants