public static void Initialize() { clnt = new TFTPClient(serverIP, port); rcvBuffer = new byte[516]; sndBuffer = new byte[516]; localFile = new BinaryReader(File.Open(localPutPath, FileMode.Open)); }
public static void Initialize() { clnt = new TFTPClient(serverIP, port); rcvBuffer = new byte[516]; sndBuffer = new byte[516]; localFile = new BinaryReader(File.Open(localPutPath, FileMode.Open)); }
public void Init() { client = new TFTPClient(tftpIP, 69); //Initialize sndBuffer = new byte[516]; rcvBuffer = new byte[516]; localFile = new BinaryReader(File.Open(localPath, FileMode.Open)); }
public static void checker(TFTPClient.FSM_Modes tftpMode) { if (tftpMode != state) { TFTPClient.FSM_Modes stateCopy = state; state = TFTPClient.FSM_Modes.INIT; Assert.AreEqual(tftpMode, stateCopy, "State mismatch: Model vs Implementation"); } }
private void DoNetSend() { if (fileName == null) { MessageBox.Show("请先选择要下载的文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } IPAddress ip; try { ip = IPAddress.Parse(txtIP.Text); } catch (Exception) { MessageBox.Show("IP地址设置有误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); txtIP.Focus(); return; } Cursor.Current = Cursors.WaitCursor; Application.DoEvents(); 载.Enabled = false; try { TFTPClient tftp = new TFTPClient(txtIP.Text); tftp.Put("Coin.bin", fileName); //MessageBox.Show("PUT finished"); } catch (TFTPClient.TFTPException tx) { MessageBox.Show("Exception in PUT: " + tx.ErrorMessage); Cursor.Current = Cursors.Default; } 载.Enabled = true; Cursor.Current = Cursors.Default; Application.DoEvents(); }
private void button2_Click(object sender, EventArgs e) { if (radioSerial.Checked == true) { send_str("reset\r"); } else if (radioNet.Checked == true) { IPAddress ip; try { ip = IPAddress.Parse(txtIP.Text); } catch (Exception) { MessageBox.Show("IP地址设置有误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); txtIP.Focus(); return; } Cursor.Current = Cursors.WaitCursor; Application.DoEvents(); try { TFTPClient tftp = new TFTPClient(txtIP.Text); tftp.sendNetCmd("reset"); //MessageBox.Show("PUT finished"); } catch (TFTPClient.TFTPException tx) { MessageBox.Show("Exception in PUT: " + tx.ErrorMessage); Cursor.Current = Cursors.Default; } Cursor.Current = Cursors.Default; Application.DoEvents(); } }
/// <summary> /// Initialze the TFTP client. Set the state to be INIT /// </summary> public static TFTPClient InitializeTestAdapter() { TFTPClient newClient = new TFTPClient("127.0.0.1", 69); newClient.initialize(); localFile = createLocalFilePath(); return newClient; }
public void Init() { client = new TFTPClient(tftpIP, 69); //Initialize rcvBuffer = new byte[516]; }
public void Init() { client = new TFTPClient(tftpIP, 69); //Initialize sndBuffer = new byte[516]; rcvBuffer = new byte[516]; localFile = new BinaryReader(File.Open(localPath, FileMode.Open)); }
public void Init() { client = new TFTPClient(tftpIP, 69); //Initialize }
static int Main(string[] args) { try { string localFilename = null; string remoteFilename = null; bool isGet = false; bool isPut = false; bool ipv6 = false; int serverPort = 69; bool showHelp = false; bool silent = false; IPAddress serverAddress = null; var settings = new TFTPClient.Settings() { ProgressInterval = TimeSpan.FromMilliseconds(200.0), OnProgress = Program.OnProgress }; var optionSet = new OptionSet { "", string.Format("TFTPClient {0}", Assembly.GetExecutingAssembly().GetName().Version.ToString(3)), "Transfers files to and from a remote computer running the TFTP service.", "", "Usage: TFTPClient [options]+ host[:port]", "", { "get", "get a file from remote to local", x => { isGet = true; } }, { "put", "put a file from local to remote", x => { isPut = true; } }, { "local=", "local filename", name => localFilename = name }, { "remote=", "remote filename", name => remoteFilename = name }, { "serverport=", "override server port (default: 69)", (int port) => serverPort = port }, { "blocksize=", "set blocksize (default: 512)", (int blocksize) => settings.BlockSize = blocksize }, { "timeout=", "set response timeout [s] (default: 2)", (int timeout) => settings.ResponseTimeout = TimeSpan.FromSeconds(timeout) }, { "retries=", "set maximum retries (default: 5)", (int retries) => settings.Retries = retries }, { "verbose", "generate verbose tracing", x => { settings.OnTrace = Program.OnTrace; } }, { "ipv6", "resolve hostname to an ipv6 address", x => { ipv6 = true; } }, { "dontfragment", "don't allow packet fragmentation (default: allowed)", x => settings.DontFragment = (x != null) }, { "silent", "don't show progress information", x => silent = (x != null) }, { "ttl=", "set time to live", (short ttl) => settings.Ttl = ttl }, { "?|h|help", "show help", x => { showHelp = true; } }, "", "You may use -, --, or / as option delimiters", "", "'host' may be specified as a hostname, ipv4 address or ipv6 address.", "To specify the port number for a ipv6 address you should put the address", "in square brackets, e.g. [::1]:69", "", "Example: (downloading a file 'image.bin' from a server at 192.168.1.23)", "\tTFTPClient /get /local=image.bin /remote=image.bin 192.168.1.23", }; var remaining = optionSet.Parse(args); if (showHelp || remaining.Count < 1) { optionSet.WriteOptionDescriptions(Console.Out); return(0); } if (silent) { settings.OnProgress = null; } if (!isGet && !isPut) { Console.Error.WriteLine("You have to specify /get or /put"); return(1); } if (localFilename == null || remoteFilename == null) { Console.Error.WriteLine("/local and /remote are mandatory"); return(1); } if (IPAddress.TryParse(remaining[0], out serverAddress)) { // now try to find whether a port was specified var components = remaining[0].Split(new string[] { serverAddress.AddressFamily == AddressFamily.InterNetworkV6 ? "]:" : ":" }, StringSplitOptions.RemoveEmptyEntries); if (components.Length > 1) { int.TryParse(components[1], out serverPort); } } else { var components = remaining[0].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); serverAddress = Dns.GetHostEntry(components[0]).AddressList.Where(x => x.AddressFamily == (ipv6 ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork)).FirstOrDefault(); if (components.Length > 1) { int.TryParse(components[1], out serverPort); } } if (serverAddress == null) { Console.Error.WriteLine("Could not resolve '{0}' to an {1} address", remaining[0], ipv6 ? "ipv6" : "ipv4"); return(1); } try { if (isPut) { TFTPClient.Upload( new IPEndPoint(serverAddress, serverPort), localFilename, remoteFilename, settings); } else { TFTPClient.Download( new IPEndPoint(serverAddress, serverPort), localFilename, remoteFilename, settings); } if (!silent) { Console.WriteLine("Transfer complete."); } return(0); } catch (Exception e) { Console.Error.WriteLine("Transfer failed: {0}", e.Message); return(1); } } catch (Exception e) { Console.Error.WriteLine("Error: {0}", e.Message); return(1); } }
public void Init() { client = new TFTPClient(tftpIP, 69); //Initialize }
public void Init() { client = new TFTPClient(tftpIP, 69); //Initialize rcvBuffer = new byte[516]; }
private void buttonStart_Click(object sender, EventArgs e) { try { if (task == null) { toolStripStatusLabel1.Text = ""; if (string.IsNullOrWhiteSpace(LocalFilename)) { MessageBox.Show(this, "Please enter a valid local filename", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrWhiteSpace(RemoteFilename)) { MessageBox.Show(this, "Please enter a valid remote filename", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext(); IPEndPoint endpoint = ResolveServer(textBoxServer.Text); string localFilename = LocalFilename; string remoteFilename = RemoteFilename; bool isDownload = IsDownload; var settings = new TFTPClient.Settings(); settings.OnProgress = OnProgress; settings.ProgressInterval = TimeSpan.FromMilliseconds(200); settings.BlockSize = Configuration.BlockSize; settings.DontFragment = Configuration.DontFragment; settings.ResponseTimeout = TimeSpan.FromSeconds(Configuration.Timeout); settings.Retries = Configuration.Retries; settings.Ttl = (short)Configuration.Ttl; panel1.Enabled = false; task = Task.Factory.StartNew( () => { if (isDownload) { TFTPClient.Download(endpoint, localFilename, remoteFilename, settings); } else { TFTPClient.Upload(endpoint, localFilename, remoteFilename, settings); } }, TaskCreationOptions.LongRunning ).ContinueWith( t => { if (t.Exception != null) { HandleException(t.Exception.InnerException); } panel1.Enabled = true; task = null; } , uiScheduler); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void checker(TFTPClient.FSM_Modes tftpMode) { Condition.IsTrue(state == tftpMode); }