You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter使用ftpconnect上传文件遇Connection reset by peer错误求助

Flutter FTPS上传报错:Connection reset by peer

执行ftpConnect.uploadFile(filePath)时触发如下错误:

-- Error: SocketException: Connection reset by peer (OS Error: Connection reset by peer, errno = 104), address = <host>, port = <port>

上传实现代码

核心上传方法

Future<void> uploadFtp(File filepath, String code) async {
  FTPConnect ftpConnect = FTPConnect('host',port:21, user:'user', pass:'pass', debug: true,securityType: SecurityType.FTPES, timeout: 30);
  await _log('Connecting to FTP');
  bool connection = await ftpConnect.connect();
  await _log('Connection : ' + (connection ? 'SUCCESSFULLY' : 'FAILED'));
    try {
      bool change = await ftpConnect.changeDirectory('palette');
      await _log(
          'Change directory : ' + (change ? 'SUCCESSFULLY' : 'FAILED'));
      String dir = path.dirname(filepath.path);
      String newName = path.join(dir, '$code.jpg');
      filepath = File(filepath.path).renameSync(newName);
      await _log('Uploading ... : ${filepath}');
      bool res = await ftpConnect.uploadFile(filepath);
      await _log('file uploaded: ' + (res ? 'SUCCESSFULLY' : 'FAILED'));
    } catch(e) {
      await _log('Error: ${e.toString()}');
    } finally {
      await ftpConnect.disconnect();
    }
}

日志辅助方法

Future<void> _log(String log) async {
  print(log);
  await Future.delayed(Duration(seconds: 1));
}

排查信息

  • 已开启debug: true,调试日志显示:FTP命令执行到PBSZ 0、PROT P后触发连接重置
  • FTP服务器使用FTPS(Explicit FTP over TLS/SSL),已通过Windows FileZilla、Android AndFTP验证配置,均能正常传输文件

内容的提问来源于stack exchange,提问作者Okazaki

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 19:50:38