【发布时间】:2021-12-27 06:46:57
【问题描述】:
我正在尝试使用ftpconnect 1.0.0 连接到 FTP 并下载文件。
有什么不明白的,所以写了一个问题。
如果你看一下连接 FTP 并下载文件的方法,它需要两个参数。
/// Download the Remote File [sRemoteName] to the local File [fFile]
Future<bool> downloadFile(
String? sRemoteName,
File fFile, {
TransferMode mode = TransferMode.binary,
FileProgress? onProgress,
bool? supportIPv6,
}) {
return FileDownload(_socket, mode, _log).downloadFile(sRemoteName, fFile,
onProgress: onProgress, supportIPV6: supportIPv6);
}
sRemoteName 是 FTP 上的文件名,fFile 是您要保存的文件吗?
如果正确的话,如何设置保存在应用中的路径?
提前感谢您的回复。
我的源代码
import 'dart:io';
import 'package:flutter/widgets.dart';
import 'package:ftpconnect/ftpconnect.dart';
class FTPServer extends ChangeNotifier{
FTPConnect? ftpConnect;
File? file;
Future<void> _fileMock(String strFileName) async {
final Directory directory = Directory('/test')
..createSync(recursive: true);
file = File('${directory.path}/$strFileName');
notifyListeners();
}
//FTP Connection
connectionFTP() async {
ftpConnect = FTPConnect('IP address', user: 'user', pass: 'password', port: portNumber);
notifyListeners();
}
//Change Dir
Future<void> changeDirectoryFTP(String strFilePath) async {
try {
bool bRes = await ftpConnect!.connect();
await ftpConnect!.changeDirectory(strFilePath);
}catch(e){
print('Error : ${e.toString()}');
}
notifyListeners();
}
//Download File
Future<void> downloadFileFTP() async{
try {
bool bRes = await ftpConnect!.connect();
await ftpConnect!.downloadFileWithRetry('FTP File Name', File name to save , pRetryCount: 1);
await ftpConnect!.disconnect();
}catch(e){
print('Error : ${e.toString()}');
}
notifyListeners();
}
}
【问题讨论】: