-
Notifications
You must be signed in to change notification settings - Fork 2
/
upload-to-cf.cs
61 lines (49 loc) · 1.43 KB
/
upload-to-cf.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
Copyright: BSD
Author: Chmouel Boudjnah <[email protected]>
*/
using System;
using System.Collections.Generic;
using com.mosso.cloudfiles;
using com.mosso.cloudfiles.domain;
using System.IO;
namespace UploadToCFCLI
{
class MainClass
{
static String username;
static String api_key;
static String chosenContainer;
static String filePath;
public static void Main (string[] args)
{
Boolean b = false;
if (args.Length != 4) {
Console.WriteLine("Usage: username api_key container object");
Environment.Exit(1);
}
username = args[0];
api_key = args[1];
chosenContainer = args[2];
filePath = args[3];
UserCredentials userCreds = new UserCredentials(username, api_key);
Connection connection = new com.mosso.cloudfiles.Connection(userCreds);
List<string> containers = connection.GetContainers();
foreach (string container in containers) {
if (container == chosenContainer)
b = true;
}
if (!b) {
Console.WriteLine("Container {0} does not seem to exist.", chosenContainer);
Environment.Exit(1);
}
if (!File.Exists(filePath)) {
Console.WriteLine("fileName {0} does not seem to exist.", filePath);
Environment.Exit(1);
}
FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
connection.PutStorageItem(chosenContainer, fileStream, Path.GetFileName(filePath));
Console.WriteLine("*success* uploaded");
}
}
}