// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Data; public partial class Dir : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void ButtonTransferAB_Click(object sender, EventArgs e) { this.Transfer(this.DisplayDir1.CurrentHost(), this.DisplayDir1.SelectedFile(), this.DisplayDir2.CurrentHost(), this.DisplayDir2.CurrentDirectory()); } protected void ButtonTransferBA_Click(object sender, EventArgs e) { this.Transfer(this.DisplayDir2.CurrentHost(), this.DisplayDir2.SelectedFile(), this.DisplayDir1.CurrentHost(), this.DisplayDir1.CurrentDirectory()); } private void Transfer(string sourceHost, string sourcePath, string targetHost, string targetDirectory) { if (sourcePath == null) { this.LabelError.Text = "No source file selected"; return; } if (targetDirectory == null) { this.LabelError.Text = "No target directory selected"; return; } string targetPath = targetDirectory; if (targetPath.EndsWith(@"\") == false) targetPath += @"\"; targetPath += Path.GetFileName(sourcePath); if (Spludlow.RemoteIO.FileExists(targetHost, targetPath) == true) { this.LabelError.Text = "Target File Already Exists: " + targetHost + ", " + targetPath; return; } long fileSize = (long)Spludlow.Call.Now(sourceHost, "Spludlow", "Spludlow.Io.Files", "FileLength", new object[] { sourcePath }); bool direct = false; if (fileSize <= 1048576 || this.CheckBoxDirect.Checked == true) direct = true; if (direct == true) { if (sourceHost == targetHost) { Spludlow.RemoteIO.FileCopy(sourceHost, sourcePath, targetPath); this.LabelError.Text = "Copy Direct: " + sourceHost + ", " + sourcePath + " -> " + targetPath; } else { Spludlow.Call.Now(targetHost, "Spludlow", "Spludlow.Call", "Download", new object[] { sourceHost, sourcePath, targetPath }); this.LabelError.Text = "Download Direct: " + targetHost + ", " + sourceHost + "@" + sourcePath + " -> " + targetHost + "@" + targetPath; } this.Refresh(); } else { string address = targetHost + ":Sys"; if (sourceHost == targetHost) { Spludlow.Call.Queue(address, "System", "System.IO.File", "Copy", new object[] { sourcePath, targetPath }); this.LabelError.Text = "Copy Queued: " + address + ", " + sourcePath + " -> " + targetPath; } else { Spludlow.Call.Queue(address, "Spludlow", "Spludlow.Call", "Download", new object[] { sourceHost, sourcePath, targetPath }); this.LabelError.Text = "Download Queued: " + address + ", " + sourceHost + "@" + sourcePath + " -> " + targetHost + "@" + targetPath; } } } protected void ButtonRefresh_Click(object sender, EventArgs e) { this.Refresh(); } private void Refresh() { this.DisplayDir1.Refresh(); this.DisplayDir2.Refresh(); } private string[] SelectedHostAndPath(string action) { if (this.DisplayDir1.SelectedFile() != null && this.DisplayDir2.SelectedFile() != null) { this.LabelError.Text = "Please only select one file to " + action; return null; } if (this.DisplayDir1.SelectedFile() == null && this.DisplayDir2.SelectedFile() == null) { this.LabelError.Text = "Please select a file to " + action; return null; } string host; string path; if (this.DisplayDir1.SelectedFile() != null) { host = this.DisplayDir1.CurrentHost(); path = this.DisplayDir1.SelectedFile(); } else { host = this.DisplayDir2.CurrentHost(); path = this.DisplayDir2.SelectedFile(); } return new string[] { host, path }; } protected void ButtonDelete_Click(object sender, EventArgs e) { string[] hostPath = this.SelectedHostAndPath("delete"); if (hostPath == null) return; string host = hostPath[0]; string path = hostPath[1]; if (this.CheckBoxSure.Checked == false) { this.LabelError.Text = "Are you sure?"; return; } try { Spludlow.RemoteIO.FileDelete(host, path); this.LabelError.Text = "Deleted: " + host + "@" + path; this.DisplayDir1.UnSelectFiles(); this.DisplayDir2.UnSelectFiles(); } catch (Exception ee) { this.LabelError.Text = ee.Message; } this.CheckBoxSure.Checked = false; } protected void ButtonRename_Click(object sender, EventArgs e) { string[] hostPath = this.SelectedHostAndPath("rename"); if (hostPath == null) return; string host = hostPath[0]; string path = hostPath[1]; if (this.CheckBoxSure.Checked == false) { this.TextBoxName.Text = Path.GetFileName(path); this.LabelError.Text = "Are you sure?"; return; } this.TextBoxName.Text = this.TextBoxName.Text.Trim(); if (this.TextBoxName.Text.Length == 0) { this.LabelError.Text = "Please enter the new file name. (Click rename without 'sure?' checked to get original filename)"; return; } string targetPath = Path.GetDirectoryName(path); if (targetPath.EndsWith(@"\") == false) targetPath += @"\"; targetPath += this.TextBoxName.Text; if (Spludlow.RemoteIO.FileExists(host, targetPath) == true) { this.LabelError.Text = "Target FileFile Already Exists: " + host + "@" + targetPath; return; } try { Spludlow.RemoteIO.FileMove(host, path, targetPath); this.LabelError.Text = "Renamed: " + host + ", " + path + " -> " + targetPath; this.TextBoxName.Text = ""; this.Refresh(); } catch (Exception ee) { this.LabelError.Text = ee.Message; } this.CheckBoxSure.Checked = false; } }