Exemplo n.º 1
0
        /*
         * Method Name:createBtn_Click
         * Description:
         *      This is a click action on the create button.  It creates a text file with the name of the text in the utility text field.
         */
        private void createBtn_Click(object sender, EventArgs e)
        {
            String fileName = utilityRTxt.Text;
            Regex  isFolder = new Regex(@"\w+\.\w+");

            if (!isFolder.IsMatch(fileName))
            {
                ftpRequest        = FtpWebRequest.Create("ftp://" + serverAddress + "/" + fileName) as FtpWebRequest;
                ftpRequest.Method = WebRequestMethods.Ftp.MakeDirectory;

                ftpRequest.Credentials = new NetworkCredential(userName, passWord);

                ftpResponse = ftpRequest.GetResponse() as FtpWebResponse;
                contentLstBx.Items.Add(ftpResponse.StatusCode);
            }
            else
            {
                ftpRequest        = FtpWebRequest.Create("ftp://" + serverAddress + "/" + fileName) as FtpWebRequest;
                ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;

                ftpRequest.Credentials = new NetworkCredential(userName, passWord);
                byte[] file;
                try
                {
                    StreamReader source = new StreamReader(utilityRTxt.Text);
                    file = Encoding.UTF8.GetBytes(source.ReadToEnd());
                    source.Close();
                }
                catch (Exception ex)
                {
                    FileCreation newfile = new FileCreation(fileName, this);
                    newfile.ShowDialog();
                    file = Encoding.UTF8.GetBytes(createdFile);
                }
                ftpRequest.ContentLength = file.Length;

                responseStream = ftpRequest.GetRequestStream();
                responseStream.Write(file, 0, file.Length);
                responseStream.Close();

                ftpResponse = ftpRequest.GetResponse() as FtpWebResponse;

                contentLstBx.Items.Add(ftpResponse.StatusCode);
            }
        }
Exemplo n.º 2
0
        /*
         * Method Name: updateBtnClick
         * Description:
         *      This is a click event for the update button.  It allows the user to edit a text file by downloading the specified file and
         *      puting it's content on a seperate form where the user can type what he/she wants.  When the user hits send, this method uploads
         *      the new file to the ftp server.
         */
        private void updateBtnClick(object sender, EventArgs e)
        {
            String fileName = utilityRTxt.Text;

            //retrieve file
            ftpRequest        = WebRequest.Create("ftp://" + serverAddress + "/" + fileName) as FtpWebRequest;
            ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;

            ftpRequest.Credentials = new NetworkCredential(userName, passWord);

            ftpResponse = ftpRequest.GetResponse() as FtpWebResponse;

            responseStream = ftpResponse.GetResponseStream();
            ftpReader      = new StreamReader(responseStream);
            //start filecreation form to edit file
            FileCreation newfile = new FileCreation(fileName, this);

            newfile.setContent(ftpReader.ReadToEnd());
            newfile.ShowDialog();
            uploadFile();
        }