-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update parsing of ls, download, and upload
- Loading branch information
1 parent
87fcb03
commit f4ae502
Showing
10 changed files
with
283 additions
and
159 deletions.
There are no files selected for viewing
34 changes: 29 additions & 5 deletions
34
Payload_Type/athena/athena/agent_code/Agent.Models/Comms/Tasks/DownloadArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
Payload_Type/athena/athena/agent_code/upload/UploadArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace upload | ||
{ | ||
public class UploadArgs | ||
{ | ||
public string path { get; set; } | ||
public string filename { get; set; } | ||
public string file { get; set; } | ||
public bool Validate(out string message) | ||
{ | ||
message = String.Empty; | ||
|
||
//If we didn't get a path set it to the current directory | ||
if (string.IsNullOrEmpty(path) || path == ".") | ||
{ | ||
path = Directory.GetCurrentDirectory(); | ||
} | ||
|
||
if(!Directory.Exists(path)) | ||
{ | ||
message = "Directory doesn't exist!"; | ||
return false; | ||
} | ||
|
||
if (!CanWriteToFolder(path)) | ||
{ | ||
message = "Path not writeable."; | ||
return false; | ||
} | ||
|
||
if (string.IsNullOrEmpty(filename)) | ||
{ | ||
message = "No filename specified"; | ||
return false; | ||
} | ||
|
||
path = Path.Combine(path, filename); | ||
return true; | ||
} | ||
private bool CanWriteToFolder(string folderPath) | ||
{ | ||
try | ||
{ | ||
var directory = Path.GetDirectoryName(folderPath); | ||
// Check if the folder exists | ||
if (Directory.Exists(directory)) | ||
{ | ||
// Try to create a temporary file in the folder | ||
string tempFilePath = Path.Combine(directory, Path.GetRandomFileName()); | ||
using (FileStream fs = File.Create(tempFilePath)) { } | ||
|
||
// If successful, delete the temporary file | ||
File.Delete(tempFilePath); | ||
|
||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
catch (Exception ep) | ||
{ | ||
// An exception occurred, indicating that writing to the folder is not possible | ||
return false; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.