Created
March 8, 2020 22:56
-
-
Save reb311ion/e9893958b4e4d7a07b1d59c2024b3cf9 to your computer and use it in GitHub Desktop.
Transfer.sh client
This file contains hidden or 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
using System; | |
using System.IO; | |
using System.Net; | |
using System.Text; | |
namespace Transfersh | |
{ | |
class Program | |
{ | |
static int Main(string[] args) | |
{ | |
if (args.Length == 0) | |
{ | |
Console.WriteLine("Transfersh.exe <FILE_PATH>"); | |
return 1; | |
} | |
else | |
{ | |
string textFile = args[0]; | |
FileInfo file = new FileInfo(textFile); | |
if (file.Exists) | |
{ | |
string text = File.ReadAllText(textFile); | |
WebRequest requestSend = WebRequest.Create("https://transfer.sh/" + file.Name); | |
requestSend.Method = "PUT"; | |
Stream dataStreamSend = requestSend.GetRequestStream(); | |
byte[] byteArray = Encoding.UTF8.GetBytes(text); | |
requestSend.ContentType = "application/x-www-form-urlencoded"; | |
requestSend.ContentLength = byteArray.Length; | |
dataStreamSend.Write(byteArray, 0, byteArray.Length); | |
dataStreamSend.Close(); | |
using (WebResponse response = (HttpWebResponse)requestSend.GetResponse()) | |
{ | |
byte[] bytes = ReadFully(response.GetResponseStream()); | |
string converted = Encoding.UTF8.GetString(bytes, 0, bytes.Length); | |
Console.WriteLine(converted); | |
} | |
} | |
return 0; | |
} | |
} | |
public static byte[] ReadFully(Stream input) | |
{ | |
byte[] buffer = new byte[16 * 1024]; | |
using (MemoryStream ms = new MemoryStream()) | |
{ | |
int read; | |
while ((read = input.Read(buffer, 0, buffer.Length)) > 0) | |
{ | |
ms.Write(buffer, 0, read); | |
} | |
return ms.ToArray(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment