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
相关产品推荐
相关产品推荐

