示例#1
0
        private void SendFtpCommandFile(String command)
        {
            
            try
            {
                // Create a temporary file
                String tempFile = Path.GetTempFileName();
                FileInfo fileInfo = new FileInfo(tempFile);
                fileInfo.Attributes = FileAttributes.Temporary;
                logger.Debug(String.Format("Created temp command file {0}", tempFile));

                // Write the command string to the file
                StreamWriter writer = File.AppendText(tempFile);
                writer.Write(command);
                writer.Flush();
                writer.Close();

                // Send the file to the Pi
                using (Ftp ftpClient = new Ftp(settings.FtpAddress, settings.FtpUser, settings.FtpPassword))
                {
                    logger.Info("Uploading command file");
                    ftpClient.upload("command.txt", tempFile);
                }

                // Delete the temporary file
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
            }
            catch (Exception ex)
            {
                // Oops.
                logger.Error(String.Format("Error while sending startx/stopx command: {0}", ex.Message));
            }
        }
示例#2
0
 private void SendPhotoButton_Click(object sender, RoutedEventArgs e)
 {
     // TODO: Put FTP photo send into a separate function for re-use during sim
     // FTP the photo to the Pi
     logger.Debug(String.Format("Opening FTP connection to {0}", settings.FtpAddress));
     try
     {
         using (Ftp ftpClient = new Ftp(settings.FtpAddress, settings.FtpUser, settings.FtpPassword))
         {
             logger.Info(String.Format("Uploading file {0}", settings.PhotoFileName));
             ftpClient.upload("tmp.tmp", settings.PhotoFileName);
             ftpClient.rename("tmp.tmp", "0.jpg");
         }
     }
     catch (WebException ex)
     {
         logger.Error(ex.ToString());
     }
     catch (Exception ex)
     {
         logger.Error(ex.ToString());
     }
     
 }
示例#3
0
        private void SendVideoButton_Click(object sender, RoutedEventArgs e)
        {
            // Determine the destination filename
            String destinationFileName = "preview_";
            destinationFileName += settings.VideoId.ToString();
            if (RepeatAndIntervalCheckBox.IsChecked == true)
            {
                destinationFileName += "_" + settings.VideoFileRepeats.ToString();
                destinationFileName += "+" + settings.VideoFileInterval.ToString();
            }
            destinationFileName += ".asf";

            //FTP The video to the Pi
            logger.Debug(String.Format("Opening FTP connection to {0}", settings.FtpAddress));
            try
            {
                using (Ftp ftpClient = new Ftp(settings.FtpAddress, settings.FtpUser, settings.FtpPassword))
                {
                    logger.Info(String.Format("Uploading video {0} to {1}", settings.VideoFileName, destinationFileName));
                    ftpClient.upload("tmp.tmp", settings.VideoFileName);
                    ftpClient.rename("tmp.tmp", destinationFileName);
                }
            }
            catch (WebException ex)
            {
                logger.Error(ex.ToString());
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
            }
        }