├── .gitattributes
├── .gitignore
├── README.md
├── UploadAndLink.sln
└── UploadAndLinkCmd
├── App.config
├── Program.cs
├── Properties
└── AssemblyInfo.cs
├── UploadAndLinkCmd.csproj
├── UploadAndPaste.hotkeyLoader.ahk
├── UploadAndPaste.hotkeyLoader.exe
├── packages.config
├── server-config.example.json
├── server-config.example2.json
└── server-config.example3.json
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
262 | /UploadAndLinkCmd/server-config.json
263 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Upload And Paste
2 |
3 | This is a small Windows tool that allows you to paste the contents of the clipboard as plaintext (removing formatting). Additionally it automatically uploads images and files on the clipboard to a server and pastes the url. This provides functionality similar to CloudApp, except on your own server for free. It supports FTP, SFTP, SCP, AWS S3, WebDav, via the included WinSCP library.
4 |
5 | Here is an example screenshot from my dev machine uploaded this way: 
6 | I simply pressed Alt-PrintScreen on my keyboard to take a screenshot of my active app, then Ctrl-Shift-V to paste the URL of the uploaded screenshot.
7 |
8 | ## Functionality
9 |
10 | 1. If content of clipboard is a file, it uploads that file to the server and pastes the public URL.
11 | 2. If content of the clipboard is an image (such as a screenshot or other raw bitmap data), it saves to a png and uploads to the server, pasting the public URL.
12 | 3. If content of clipboard is rich text or HTML, it pastes the plain text without formatting.
13 | 4. If none of the above, it silently aborts.
14 |
15 | In all supported cases it pastes a plain text, easily sharable representation of the content.
16 |
17 | ## Setup
18 |
19 | 1. Either build from source in Visual Studio 2017 or download the pre-built binary from [http://rog.gy/share/UploadAndPaste.zip](http://rog.gy/share/UploadAndPaste.zip) (yes that was uploaded using this tool!)
20 | 2. Rename one of the `server-config.example.json` files to `server-config.json` and fill in the details.
21 | * `"baseUploadPath": "/var/www/mysite/"`
22 | This is the path relative to the root of your server where files should be uploaded
23 |
24 | * `"baseUrl":"https://example.com/"`
25 | This is the root public URL that the files are accessible from.
26 |
27 | * `"fileDir": "share/"` *Optional*
28 | You can specify a subdirectory where non-screenshot files are uploaded. Since these files may be of any type, you should configure your server/host to serve these files directly without running/executing them (for example a shared hosting provider may assume you want to execute a php script, which may result in unforeseen issues)
29 |
30 | * `"ssDir": "ss/"` *Optional*
31 | You can specify a subdirectory where screenshots uploaded.
32 |
33 | * The remaining items are configuration for WinSCP to connect to the server. You can generate the values directly via WinSCP as documented here: https://winscp.net/eng/docs/ui_generateurl#code
34 |
35 | 3. If you want to use a hotkey other than Ctrl-Shift-V, you need to modify `UploadAndPaste.hotkeyLoader.ahk` and use [AutoHotKey](https://www.autohotkey.com/) to recompile the script
36 | 4. Run `UploadAndPaste.hotkeyLoader.exe` or set it to run on startup. Depending on how you set it to run on startup, you may need to ensure the working directory is specified.
37 | 5. With some data on the clipboard and a focused text area to paste into, press Ctrl-Shift-V to test it out.
38 |
39 | ## Known Issues
40 |
41 | 1. When there are multiple files on the clipboard, it only uploads one.
42 | 2. There is no progress indicatior, so large uploads may appear to stall on slow connections. The mouse cursor changes to the wait cursor so you know it's working.
43 |
44 | ## Why
45 |
46 | I created this tool to scratch my own itch. I hope you find it useful! Feel free to report any bugs or suggestions you may find. More information about this [clipboard upload tool](https://rogerpincombe.com/upload-and-paste) on [my homepage](https://rogerpincombe.com).
--------------------------------------------------------------------------------
/UploadAndLink.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.28307.136
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UploadAndLinkCmd", "UploadAndLinkCmd\UploadAndLinkCmd.csproj", "{123B3797-D176-4409-91AB-40A667E0455B}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9A58A184-709E-4AEC-AE68-4A81C8F67327}"
9 | ProjectSection(SolutionItems) = preProject
10 | README.md = README.md
11 | EndProjectSection
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|Any CPU = Debug|Any CPU
16 | Release|Any CPU = Release|Any CPU
17 | EndGlobalSection
18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
19 | {123B3797-D176-4409-91AB-40A667E0455B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20 | {123B3797-D176-4409-91AB-40A667E0455B}.Debug|Any CPU.Build.0 = Debug|Any CPU
21 | {123B3797-D176-4409-91AB-40A667E0455B}.Release|Any CPU.ActiveCfg = Release|Any CPU
22 | {123B3797-D176-4409-91AB-40A667E0455B}.Release|Any CPU.Build.0 = Release|Any CPU
23 | EndGlobalSection
24 | GlobalSection(SolutionProperties) = preSolution
25 | HideSolutionNode = FALSE
26 | EndGlobalSection
27 | GlobalSection(ExtensibilityGlobals) = postSolution
28 | SolutionGuid = {2C185059-788D-4503-9733-E9EEC8C19FCE}
29 | EndGlobalSection
30 | EndGlobal
31 |
--------------------------------------------------------------------------------
/UploadAndLinkCmd/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/UploadAndLinkCmd/Program.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json.Linq;
2 | using System;
3 | using System.Diagnostics;
4 | using System.Drawing;
5 | using System.Drawing.Imaging;
6 | using System.IO;
7 | using System.Runtime.InteropServices;
8 | using System.Security.Cryptography;
9 | using System.Threading;
10 | using System.Windows.Forms;
11 | using WinSCP;
12 |
13 | namespace UploadAndLinkCmd
14 | {
15 | class Program
16 | {
17 | private static string baseUploadPath;
18 | private static string baseUrl;
19 | private static string fileDir = "";
20 | private static string ssDir = "";
21 |
22 | private static SessionOptions sessionOptions = new SessionOptions();
23 |
24 | static void LoadConfig(string configFilePath)
25 | {
26 | var config = JObject.Parse(File.ReadAllText(configFilePath));
27 |
28 | if (config.ContainsKey("baseUploadPath"))
29 | baseUploadPath = config.Value("baseUploadPath");
30 | else
31 | throw new InvalidOperationException("No key 'baseUploadPath' in server-config.json");
32 |
33 | if (config.ContainsKey("baseUrl"))
34 | baseUrl = config.Value("baseUrl");
35 | else
36 | throw new InvalidOperationException("No key 'baseUrl' in server-config.json");
37 |
38 | if (config.ContainsKey("fileDir"))
39 | fileDir = config.Value("fileDir");
40 | if (config.ContainsKey("ssDir"))
41 | ssDir = config.Value("ssDir");
42 |
43 | if (config.ContainsKey("Protocol"))
44 | sessionOptions.Protocol = (Protocol)Enum.Parse(typeof(Protocol), config.Value("Protocol"));
45 | else
46 | throw new InvalidOperationException("No key 'Protocol' in server-config.json. Likely you should include 'Protocol':'Sftp' or 'Protocol':'Ftp'");
47 |
48 | if (config.ContainsKey("HostName"))
49 | sessionOptions.HostName = config.Value("HostName");
50 |
51 | if (config.ContainsKey("UserName"))
52 | sessionOptions.UserName = config.Value("UserName");
53 |
54 | if (config.ContainsKey("SshHostKeyFingerprint"))
55 | sessionOptions.SshHostKeyFingerprint = config.Value("SshHostKeyFingerprint");
56 |
57 | if (config.ContainsKey("SshPrivateKeyPath"))
58 | sessionOptions.SshPrivateKeyPath = config.Value("SshPrivateKeyPath");
59 |
60 | if (config.ContainsKey("SshHostKeyFingerprint"))
61 | sessionOptions.SshHostKeyFingerprint = config.Value("SshHostKeyFingerprint");
62 |
63 |
64 | if (config.ContainsKey("FtpMode"))
65 | sessionOptions.FtpMode = (FtpMode)Enum.Parse(typeof(FtpMode), config.Value("FtpMode"));
66 |
67 | if (config.ContainsKey("FtpSecure"))
68 | sessionOptions.FtpSecure = (FtpSecure)Enum.Parse(typeof(FtpSecure), config.Value("FtpSecure"));
69 |
70 | if (config.ContainsKey("GiveUpSecurityAndAcceptAnySshHostKey"))
71 | sessionOptions.GiveUpSecurityAndAcceptAnySshHostKey = config.Value("GiveUpSecurityAndAcceptAnySshHostKey");
72 |
73 | if (config.ContainsKey("GiveUpSecurityAndAcceptAnyTlsHostCertificate"))
74 | sessionOptions.GiveUpSecurityAndAcceptAnyTlsHostCertificate = config.Value("GiveUpSecurityAndAcceptAnyTlsHostCertificate");
75 |
76 | if (config.ContainsKey("Password"))
77 | sessionOptions.Password = config.Value("Password");
78 |
79 | if (config.ContainsKey("PortNumber"))
80 | sessionOptions.PortNumber = config.Value("PortNumber");
81 |
82 | if (config.ContainsKey("PrivateKeyPassphrase"))
83 | sessionOptions.PrivateKeyPassphrase = config.Value("PrivateKeyPassphrase");
84 |
85 | if (config.ContainsKey("TimeoutInMilliseconds"))
86 | sessionOptions.TimeoutInMilliseconds = config.Value("TimeoutInMilliseconds");
87 | else if (config.ContainsKey("Timeout"))
88 | sessionOptions.TimeoutInMilliseconds = config.Value("Timeout");
89 |
90 |
91 | if (config.ContainsKey("TlsClientCertificatePath"))
92 | sessionOptions.TlsClientCertificatePath = config.Value("TlsClientCertificatePath");
93 |
94 | if (config.ContainsKey("TlsHostCertificateFingerprint"))
95 | sessionOptions.TlsHostCertificateFingerprint = config.Value("TlsHostCertificateFingerprint");
96 |
97 | if (config.ContainsKey("WebdavRoot"))
98 | sessionOptions.WebdavRoot = config.Value("WebdavRoot");
99 |
100 | if (config.ContainsKey("WebdavSecure"))
101 | sessionOptions.WebdavSecure = config.Value("WebdavSecure");
102 |
103 | }
104 |
105 | [STAThread]
106 | static void Main(string[] args)
107 | {
108 | if (Clipboard.ContainsImage())
109 | Output(UploadImage(Clipboard.GetImage() as Bitmap));
110 | else if (Clipboard.ContainsFileDropList())
111 | Output(UploadFile(new FileInfo(Clipboard.GetFileDropList()[0])));
112 | else if (Clipboard.ContainsText())
113 | {
114 | Thread.Sleep(100); // Sometimes there are issue with focus if we do this too fast
115 | Output(Clipboard.GetText(TextDataFormat.UnicodeText));
116 | }
117 | else
118 | {
119 | Debug.WriteLine("no clipboard data");
120 | }
121 | }
122 |
123 | private static string GetCBText()
124 | {
125 | string text = Clipboard.GetText(TextDataFormat.UnicodeText);
126 | if (string.IsNullOrWhiteSpace(text))
127 | text = Clipboard.GetText(TextDataFormat.Text);
128 | if (string.IsNullOrWhiteSpace(text))
129 | text = Clipboard.GetText(TextDataFormat.Rtf);
130 |
131 | return text;
132 | }
133 |
134 | private static void Output(string text)
135 | {
136 | Clipboard.SetText(text);
137 |
138 | text = text
139 | .Replace("{", "{`{")
140 | .Replace("}", "{}}")
141 | .Replace("{`{", "{{}")
142 | .Replace("+", "{+}")
143 | .Replace("^", "{^}")
144 | .Replace("%", "{%}")
145 | .Replace("~", "{~}")
146 | .Replace("(", "{(}")
147 | .Replace(")", "{)}")
148 | .Replace("[", "{[}")
149 | .Replace("]", "{]}")
150 | .Replace(Environment.NewLine, "{Enter}")
151 | .Replace("\n", "{Enter}");
152 |
153 | Debug.WriteLine(text);
154 | SendKeys.SendWait(text);
155 | }
156 |
157 | private static string UploadFile(FileInfo file)
158 | {
159 | try
160 | {
161 | LoadConfig("server-config.json");
162 | }
163 | catch (Exception ex)
164 | {
165 | MessageBox.Show(ex.ToString());
166 | throw;
167 | }
168 |
169 |
170 |
171 | IntPtr normalCursor = CopyIcon(LoadCursor(IntPtr.Zero, (int)OCR_NORMAL));
172 | IntPtr iBeamCursor = CopyIcon(LoadCursor(IntPtr.Zero, (int)OCR_IBEAM));
173 |
174 | try
175 | {
176 | SetSystemCursor(CopyIcon(LoadCursor(IntPtr.Zero, (int)OCR_APPSTARTING)), OCR_NORMAL);
177 | SetSystemCursor(CopyIcon(LoadCursor(IntPtr.Zero, (int)OCR_APPSTARTING)), OCR_IBEAM);
178 |
179 |
180 | using (Session session = new Session())
181 | {
182 | // Connect
183 | session.Open(sessionOptions);
184 |
185 | // Upload files
186 | TransferOptions transferOptions = new TransferOptions();
187 | transferOptions.TransferMode = TransferMode.Binary;
188 |
189 | TransferOperationResult transferResult;
190 | transferResult =
191 | session.PutFiles(file.FullName, baseUploadPath + fileDir + file.Name.Replace(" ", "_"), false, transferOptions);
192 |
193 | // Throw on any error
194 | transferResult.Check();
195 |
196 | return baseUrl + fileDir + file.Name.Replace(" ", "_");
197 | }
198 | }
199 | catch (Exception ex)
200 | {
201 | MessageBox.Show(ex.ToString());
202 | throw;
203 | }
204 | finally
205 | {
206 | SetSystemCursor(normalCursor, OCR_NORMAL);
207 | SetSystemCursor(iBeamCursor, OCR_IBEAM);
208 |
209 | }
210 |
211 | }
212 |
213 | private static string UploadImage(Bitmap cbImage)
214 | {
215 | try
216 | {
217 | LoadConfig("server-config.json");
218 | }
219 | catch (Exception ex)
220 | {
221 | MessageBox.Show(ex.ToString());
222 | throw;
223 | }
224 |
225 |
226 |
227 | IntPtr normalCursor = CopyIcon(LoadCursor(IntPtr.Zero, (int)OCR_NORMAL));
228 | IntPtr iBeamCursor = CopyIcon(LoadCursor(IntPtr.Zero, (int)OCR_IBEAM));
229 |
230 | try
231 | {
232 | SetSystemCursor(CopyIcon(LoadCursor(IntPtr.Zero, (int)OCR_APPSTARTING)), OCR_NORMAL);
233 | SetSystemCursor(CopyIcon(LoadCursor(IntPtr.Zero, (int)OCR_APPSTARTING)), OCR_IBEAM);
234 |
235 | byte[] rawImageData = new byte[Math.Min(2048 * 2048, cbImage.Width * cbImage.Height)];
236 | BitmapData bmpd = cbImage.LockBits(new Rectangle(0, 0, cbImage.Width, cbImage.Height),
237 | ImageLockMode.ReadOnly,
238 | PixelFormat.Format32bppArgb);
239 | Marshal.Copy(bmpd.Scan0, rawImageData, 0, rawImageData.Length);
240 | cbImage.UnlockBits(bmpd);
241 | MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
242 | byte[] hash = md5.ComputeHash(rawImageData);
243 |
244 |
245 | string tmpFile = BitConverter.ToString(hash).Replace("-", "").ToLower().PadRight(10, '0').Substring(0, 10) + ".png";
246 |
247 | cbImage.Save(Path.GetTempPath() + tmpFile, System.Drawing.Imaging.ImageFormat.Png);
248 |
249 | using (Session session = new Session())
250 | {
251 | // Connect
252 | session.Open(sessionOptions);
253 |
254 | // Upload files
255 | TransferOptions transferOptions = new TransferOptions();
256 | transferOptions.TransferMode = TransferMode.Binary;
257 |
258 | TransferOperationResult transferResult;
259 | transferResult =
260 | session.PutFiles(Path.GetTempPath() + tmpFile, baseUploadPath + ssDir + tmpFile, false, transferOptions);
261 |
262 | // Throw on any error
263 | transferResult.Check();
264 |
265 | File.Delete(Path.GetTempPath() + tmpFile);
266 |
267 | return baseUrl + ssDir + tmpFile;
268 |
269 |
270 | }
271 | }
272 | catch (Exception ex)
273 | {
274 | MessageBox.Show(ex.ToString());
275 | throw;
276 | }
277 | finally
278 | {
279 | SetSystemCursor(normalCursor, OCR_NORMAL);
280 | SetSystemCursor(iBeamCursor, OCR_IBEAM);
281 | }
282 |
283 |
284 | }
285 |
286 | [DllImport("user32.dll")]
287 | static extern bool SetSystemCursor(IntPtr hcur, uint id);
288 |
289 | [DllImport("user32.dll")]
290 | static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName);
291 |
292 |
293 | [DllImport("user32.dll")]
294 | public static extern IntPtr CopyIcon(IntPtr pcur);
295 |
296 | private const uint OCR_IBEAM = 32513;
297 | private const uint OCR_NORMAL = 32512;
298 | private const uint OCR_APPSTARTING = 32650;
299 | }
300 | }
301 |
--------------------------------------------------------------------------------
/UploadAndLinkCmd/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Upload and Paste")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Roger Pincombe")]
12 | [assembly: AssemblyProduct("Upload and Paste Tool")]
13 | [assembly: AssemblyCopyright("Copyright ©2018 Roger Pincombe")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("123b3797-d176-4409-91ab-40a667e0455b")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/UploadAndLinkCmd/UploadAndLinkCmd.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {123B3797-D176-4409-91AB-40A667E0455B}
8 | WinExe
9 | UploadAndLinkCmd
10 | UploadAndPaste
11 | v4.7.2
12 | 512
13 | true
14 | true
15 |
16 |
17 |
18 |
19 | AnyCPU
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 | UploadAndLinkCmd.Program
39 |
40 |
41 |
42 | ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | ..\packages\WinSCP.5.13.5\lib\net\WinSCPnet.dll
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | Always
70 |
71 |
72 |
73 |
74 |
75 | PreserveNewest
76 |
77 |
78 |
79 |
80 |
81 |
82 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/UploadAndLinkCmd/UploadAndPaste.hotkeyLoader.ahk:
--------------------------------------------------------------------------------
1 | +^v::
2 | Send {Blind}{Ctrl up}
3 | Send {Blind}{Shift up}
4 | Run, "UploadAndPaste.exe"
--------------------------------------------------------------------------------
/UploadAndLinkCmd/UploadAndPaste.hotkeyLoader.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OkGoDoIt/UploadAndPaste/1299fbabdcabea2297f23e881c245c17ef8fd70f/UploadAndLinkCmd/UploadAndPaste.hotkeyLoader.exe
--------------------------------------------------------------------------------
/UploadAndLinkCmd/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/UploadAndLinkCmd/server-config.example.json:
--------------------------------------------------------------------------------
1 | {
2 | "Protocol": "Sftp",
3 | "HostName": "example.com",
4 | "UserName": "root",
5 | "SshHostKeyFingerprint": "ssh-ed25519 256 Jgd3476348hg8BG88g8g787g8787G98HNFD45SCJHiw=",
6 | "SshPrivateKeyPath": "C:\\Users\\me\\.ssh\\id-rsa.ppk",
7 | "baseUploadPath":"/var/www/mysite/",
8 | "baseUrl":"https://example.com/",
9 | "fileDir": "share/",
10 | "ssDir": "ss/"
11 | }
12 |
--------------------------------------------------------------------------------
/UploadAndLinkCmd/server-config.example2.json:
--------------------------------------------------------------------------------
1 | {
2 | "Protocol": "S3",
3 | "HostName": "s3.amazonaws.com",
4 | "PortNumber": 443,
5 | "UserName": "EUJBCIU47839HCR98HS7",
6 | "Password": "kjgs8793dh9823chern8hnbGH897FHRE890hn49a",
7 | "baseUploadPath":"bucketName/",
8 | "baseUrl":"https://myPublicS3URLroot.amazon-s3.com/"
9 | }
10 |
--------------------------------------------------------------------------------
/UploadAndLinkCmd/server-config.example3.json:
--------------------------------------------------------------------------------
1 | {
2 | "Protocol": "Ftp",
3 | "HostName": "mysite.com",
4 | "PortNumber": 21,
5 | "UserName": "username",
6 | "Password": "Pa$$w0rd",
7 | "baseUploadPath": "shares/",
8 | "baseUrl": "http://www.mysite.com/shares/"
9 | }
10 |
--------------------------------------------------------------------------------