Help us understand the problem. What is going on with this article?

ドロップして一つのファイルを転送するソフトを作りました。

2018-12-01_1809.png

ドロップして一つのファイルを転送するソフトを作りました。
こんなのどうしているのかと疑問を持つ人もいると思いますが
業務上、こんなソフトが要るという会社などもいるのではないかと思いで作りました。

ダウンロードはこちらから
https://zip358.com/tool/DropFTP.zip

ソースコードは下記になります。
※FTP部分はWinSCPのライブラリを使用しています。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinSCP;

namespace dropFTP
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void upbtn_Click(object sender, EventArgs e)
        {

            String err = "";

            if (hostText.Text == "") {
                err += "ホスト名が設定されていません\n";
            }

            if (idText.Text == "")
            {
                err += "IDが設定されていません\n";
            }

            if (passText.Text == "")
            {
                err += "passが設定されていません\n";
            }

            if (remText.Text == "")
            {
                err += "アップロード場所が設定されていません\n";
            }

            if (uplab.Text == "")
            {
                err += "アップロードファイルが設定されていません\n";
            }

            var RadioGroup = groupFTP.Controls.OfType<RadioButton>().SingleOrDefault(rb => rb.Checked == true);
            if (RadioGroup == null) {
                err += "アップロード環境が設定されていません\n";
            }

            if (err != "")
            {
                MessageBox.Show(err);
            }
            else {
                if (RadioGroup.Text == "FTP") {
                    upFTP();
                }
                if (RadioGroup.Text == "SFTP")
                {
                    upSFTP();
                }

            }
        }

            private int upFTP() {
            try
            {
                // Setup session options
                SessionOptions sessionOptions = new SessionOptions
                {
                    Protocol = Protocol.Ftp,
                    HostName = hostText.Text,
                    UserName = idText.Text,
                    Password = passText.Text,
                    PortNumber =int.Parse(portText.Text)
                };

                using (Session session = new Session())
                {
                    // Connect
                    session.Open(sessionOptions);

                    // Upload files
                    TransferOptions transferOptions = new TransferOptions();
                    transferOptions.TransferMode = TransferMode.Binary;

                    TransferOperationResult transferResult;
                    if (remText.Text.EndsWith("/"))
                    {
                        transferResult = session.PutFiles(@uplab.Text, remText.Text, false, transferOptions);
                    }
                    else
                    {
                        transferResult = session.PutFiles(@uplab.Text, remText.Text + "/", false, transferOptions);
                    }
                    // Throw on any error
                    transferResult.Check();

                    // Print results
                    foreach (TransferEventArgs transfer in transferResult.Transfers)
                    {
                        MessageBox.Show("アップロードしました");
                    }
                }

                return 0;
            }
            catch (Exception e)
            {

                MessageBox.Show("Error: {0}" + e);
                return 1;
            }

        }
        private int upSFTP()
            {
                try
                {
                    // Setup session options
                    SessionOptions sessionOptions = new SessionOptions
                    {
                        Protocol = Protocol.Sftp,
                        HostName = hostText.Text,
                        UserName = idText.Text,
                        Password = passText.Text,
                        PortNumber = int.Parse(portText.Text),
                        GiveUpSecurityAndAcceptAnySshHostKey = true
                    };

                using (Session session = new Session())
                {
                    // Connect
                    session.Open(sessionOptions);

                    // Upload files
                    TransferOptions transferOptions = new TransferOptions();
                    transferOptions.TransferMode = TransferMode.Binary;

                    TransferOperationResult transferResult;
                    if (remText.Text.EndsWith("/")) { 
                        transferResult = session.PutFiles(@uplab.Text, remText.Text, false, transferOptions);
                    } else { 
                        transferResult = session.PutFiles(@uplab.Text, remText.Text + "/", false, transferOptions);
                    }
                        // Throw on any error
                        transferResult.Check();

                        // Print results
                        foreach (TransferEventArgs transfer in transferResult.Transfers)
                        {
                        MessageBox.Show("アップロードしました");
                        }
                    }

                    return 0;
                }
                catch (Exception e)
                {

                    MessageBox.Show("Error: {0}" + e);
                    return 1;
                }

            }

            private void Form1_DragDrop(object sender, DragEventArgs e) {
            //e.Effect = DragDropEffects.Copy;
            string[] fileName = (string[])e.Data.GetData(DataFormats.FileDrop, false);
            uplab.Text = fileName[0];

        }

        private void Form1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
        }

        private void radioSFTP_CheckedChanged(object sender, EventArgs e)
        {
            portText.Text = "22";
        }

        private void radioFTP_CheckedChanged(object sender, EventArgs e)
        {
            portText.Text = "21";
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.MaximumSize = this.Size;
            this.MinimumSize = this.Size;
        }
    }


}

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away