@@ -3,98 +3,98 @@ import 'dart:io';
33import 'package:ftpconnect/ftpconnect.dart' ;
44
55void main () async {
6- final FTPConnect _ftpConnect = new FTPConnect (
6+ final FTPConnect ftpConnect = FTPConnect (
77 "users.on.net" ,
88 user: "pvpt" ,
99 pass: "Lachdhaf" ,
1010 showLog: true ,
1111 );
1212
1313 ///an auxiliary function that manage showed log to UI
14- Future <void > _log (String log) async {
14+ Future <void > log (String log) async {
1515 print (log);
1616 await Future .delayed (Duration (seconds: 1 ));
1717 }
1818
1919 ///mock a file for the demonstration example
20- Future <File > _fileMock ({fileName = 'FlutterTest.txt' , content = '' }) async {
20+ Future <File > fileMock ({fileName = 'FlutterTest.txt' , content = '' }) async {
2121 final Directory directory = Directory ('/test' )..createSync (recursive: true );
2222 final File file = File ('${directory .path }/$fileName ' );
2323 await file.writeAsString (content);
2424 return file;
2525 }
2626
27- Future <void > _uploadStepByStep () async {
27+ Future <void > uploadStepByStep () async {
2828 try {
29- await _log ('Connecting to FTP ...' );
30- await _ftpConnect .connect ();
31- await _ftpConnect .changeDirectory ('upload' );
32- File fileToUpload = await _fileMock (
29+ await log ('Connecting to FTP ...' );
30+ await ftpConnect .connect ();
31+ await ftpConnect .changeDirectory ('upload' );
32+ File fileToUpload = await fileMock (
3333 fileName: 'uploadStepByStep.txt' , content: 'uploaded Step By Step' );
34- await _log ('Uploading ...' );
35- await _ftpConnect .uploadFile (fileToUpload);
36- await _log ('file uploaded sucessfully' );
37- await _ftpConnect .disconnect ();
34+ await log ('Uploading ...' );
35+ await ftpConnect .uploadFile (fileToUpload);
36+ await log ('file uploaded sucessfully' );
37+ await ftpConnect .disconnect ();
3838 } catch (e) {
39- await _log ('Error: ${e .toString ()}' );
39+ await log ('Error: ${e .toString ()}' );
4040 }
4141 }
4242
43- Future <void > _uploadWithRetry () async {
43+ Future <void > uploadWithRetry () async {
4444 try {
45- File fileToUpload = await _fileMock (
45+ File fileToUpload = await fileMock (
4646 fileName: 'uploadwithRetry.txt' , content: 'uploaded with Retry' );
47- await _log ('Uploading ...' );
48- await _ftpConnect .connect ();
49- await _ftpConnect .changeDirectory ('upload' );
47+ await log ('Uploading ...' );
48+ await ftpConnect .connect ();
49+ await ftpConnect .changeDirectory ('upload' );
5050 bool res =
51- await _ftpConnect .uploadFileWithRetry (fileToUpload, pRetryCount: 2 );
52- await _log ('file uploaded: ' + ( res ? 'SUCCESSFULLY' : 'FAILED' ) );
53- await _ftpConnect .disconnect ();
51+ await ftpConnect .uploadFileWithRetry (fileToUpload, pRetryCount: 2 );
52+ await log ('file uploaded: ${ res ? 'SUCCESSFULLY' : 'FAILED' }' );
53+ await ftpConnect .disconnect ();
5454 } catch (e) {
55- await _log ('Downloading FAILED: ${e .toString ()}' );
55+ await log ('Downloading FAILED: ${e .toString ()}' );
5656 }
5757 }
5858
59- Future <void > _downloadWithRetry () async {
59+ Future <void > downloadWithRetry () async {
6060 try {
61- await _log ('Downloading ...' );
61+ await log ('Downloading ...' );
6262
6363 String fileName = '../512KB.zip' ;
64- await _ftpConnect .connect ();
64+ await ftpConnect .connect ();
6565 //here we just prepare a file as a path for the downloaded file
66- File downloadedFile = await _fileMock (fileName: 'downloadwithRetry.txt' );
67- bool res = await _ftpConnect
66+ File downloadedFile = await fileMock (fileName: 'downloadwithRetry.txt' );
67+ bool res = await ftpConnect
6868 .downloadFileWithRetry (fileName, downloadedFile, pRetryCount: 2 );
69- await _log ( 'file downloaded ' +
70- ( res ? 'path: ${downloadedFile .path }' : 'FAILED' ) );
71- await _ftpConnect .disconnect ();
69+ await log (
70+ 'file downloaded ${ res ? 'path: ${downloadedFile .path }' : 'FAILED' }' );
71+ await ftpConnect .disconnect ();
7272 } catch (e) {
73- await _log ('Downloading FAILED: ${e .toString ()}' );
73+ await log ('Downloading FAILED: ${e .toString ()}' );
7474 }
7575 }
7676
77- Future <void > _downloadStepByStep () async {
77+ Future <void > downloadStepByStep () async {
7878 try {
79- await _log ('Connecting to FTP ...' );
79+ await log ('Connecting to FTP ...' );
8080
81- await _ftpConnect .connect ();
81+ await ftpConnect .connect ();
8282
83- await _log ('Downloading ...' );
83+ await log ('Downloading ...' );
8484 String fileName = '../512KB.zip' ;
8585
8686 //here we just prepare a file as a path for the downloaded file
87- File downloadedFile = await _fileMock (fileName: 'downloadStepByStep.txt' );
88- await _ftpConnect .downloadFile (fileName, downloadedFile);
89- await _log ('file downloaded path: ${downloadedFile .path }' );
90- await _ftpConnect .disconnect ();
87+ File downloadedFile = await fileMock (fileName: 'downloadStepByStep.txt' );
88+ await ftpConnect .downloadFile (fileName, downloadedFile);
89+ await log ('file downloaded path: ${downloadedFile .path }' );
90+ await ftpConnect .disconnect ();
9191 } catch (e) {
92- await _log ('Downloading FAILED: ${e .toString ()}' );
92+ await log ('Downloading FAILED: ${e .toString ()}' );
9393 }
9494 }
9595
96- await _uploadStepByStep ();
97- await _uploadWithRetry ();
98- await _downloadWithRetry ();
99- await _downloadStepByStep ();
96+ await uploadStepByStep ();
97+ await uploadWithRetry ();
98+ await downloadWithRetry ();
99+ await downloadStepByStep ();
100100}
0 commit comments