forked from robinrodricks/FluentFTP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUploadFile.cs
45 lines (32 loc) · 1.68 KB
/
UploadFile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using FluentFTP;
namespace Examples {
internal static class UploadFileExample {
public static void UploadFile() {
using (var ftp = new FtpClient("127.0.0.1", "ftptest", "ftptest")) {
ftp.Connect();
// upload a file to an existing FTP directory
ftp.UploadFile(@"D:\Github\FluentFTP\README.md", "/public_html/temp/README.md");
// upload a file and ensure the FTP directory is created on the server
ftp.UploadFile(@"D:\Github\FluentFTP\README.md", "/public_html/temp/README.md", FtpRemoteExists.Overwrite, true);
// upload a file and ensure the FTP directory is created on the server, verify the file after upload
ftp.UploadFile(@"D:\Github\FluentFTP\README.md", "/public_html/temp/README.md", FtpRemoteExists.Overwrite, true, FtpVerify.Retry);
}
}
public static async Task UploadFileAsync() {
var token = new CancellationToken();
using (var ftp = new AsyncFtpClient("127.0.0.1", "ftptest", "ftptest")) {
await ftp.Connect(token);
// upload a file to an existing FTP directory
await ftp.UploadFile(@"D:\Github\FluentFTP\README.md", "/public_html/temp/README.md", token: token);
// upload a file and ensure the FTP directory is created on the server
await ftp.UploadFile(@"D:\Github\FluentFTP\README.md", "/public_html/temp/README.md", FtpRemoteExists.Overwrite, true, token: token);
// upload a file and ensure the FTP directory is created on the server, verify the file after upload
await ftp.UploadFile(@"D:\Github\FluentFTP\README.md", "/public_html/temp/README.md", FtpRemoteExists.Overwrite, true, FtpVerify.Retry, token: token);
}
}
}
}