DropFTPを配布。

2018.12.01

Logging

ドップして一つのファイルを転送するソフトを作りました。
こんなのどうしているのかと疑問を持つ人もいると思いますが
業務上、こんなソフトが要るという会社などもいるのではないかと
思いで作りました。
ダウンロードはこちらから
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;
        }
    }
}

著者名  @taoka_toshiaki

※この記事は著者が30代前半に書いたものです.

Profile
高知県在住の@taoka_toshiakiです、記事を読んで頂きありがとうございます.
数十年前から息を吸うように日々記事を書いてます.たまに休んだりする日もありますがほぼ毎日投稿を心掛けています😅.
SNSも使っています、フォロー、いいね、シェア宜しくお願い致します🙇.
SNS::@taoka_toshiaki

タグ

358, Collections, com, ComponentModel, data, Drawing, DropFTP, Forms, FTP, Generic, Linq, System, Tasks, Text, Threading, tool, using, Wi, Windows, WinSCP, zip, コード, こちら, ソース, ソフト, ダウンロード, ドップ, ファイル, ライブラリ, 一つ, 下記, , 会社, 使用, 業務, 疑問, 転送, 部分, 配布,

C#SFTPでダウンロードするプログラムの作り方。

2016.12.06

Logging


C#SFTPでダウンロードするプログラムの作り方。
いろいろ調べた結果、こんだけのコードでSFTPでダウンロードする事が
判明。タダシ!!ライブラリが必要なので下記のリンクからTamir.SharpSSH.dll
のライブラリを参照してあげてください。そうすることでSFTPのダウンロードが
可能になります。FTPでの接続方法とかは結構出回っていますが、SFTPの接続プログラムって
あまり落ちてません。ちなみに、その他のライブラリを使う方法にWinSCPのライブラリを
使う方法やSSH.Netのライブラリを使う方法があります。

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 Tamir.SharpSsh;
namespace ftp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Sftp sftp = new Sftp("192.168.11.1", "id", "pass");
            sftp.Connect();
            sftp.Get("/www/html/hoge.mp4", "C:\\Users\\hoge\\Documents\\hoge.mp4");
            sftp.Close();
            MessageBox.Show("キタ━━━━(゚∀゚)━━━━!!");
        }
    }
}

https://ja.osdn.net/projects/sfnet_sharpssh/downloads/SharpSSH/1.1.1.13/SharpSSH-1.1.1.13.bin.zip/

著者名  @taoka_toshiaki

※この記事は著者が30代前半に書いたものです.

Profile
高知県在住の@taoka_toshiakiです、記事を読んで頂きありがとうございます.
数十年前から息を吸うように日々記事を書いてます.たまに休んだりする日もありますがほぼ毎日投稿を心掛けています😅.
SNSも使っています、フォロー、いいね、シェア宜しくお願い致します🙇.
SNS::@taoka_toshiaki

タグ

Collections.Generic, Documents, Form, FTP, hoge, InitializeComponent, object sender, quot, SFTP, Sftp sftp, sftp.Close, System.Text, users, using, using System.ComponentModel, using System.Drawing, using System.Linq, using System.Threading.Tasks, WinSCP, タダシ,

WinSCPというソフトが有るのだけど。

2015.07.16

Logging


WinSCPというソフトが有るのだけど自分はこのソフト、FTPのソフトだと思い込んでいたけど・・。SCPという名前の通りSCP(転送プロトコル)機能がついてたりする。面倒くさい事をさらっとやってくれるフリーソフトなわけです。そうとは知らず今までインストールすることが無かったんですけど、この度、インストールしました。ちなみに何が良いかというとFTPサービスをサーバ環境へインストールしなくてもファイルのアップロードが可能だということです。FTPがインストールされていない環境だととても重宝しそうな気がします。
ダウンロードはこちらから、WinSCP
メモがてらにもう一つ、大量のsqlデータを一括でインポートしなくてはならなくなり、昨日、調べていたらこのようなコマンドで解決することがわかりました。まず、Linuxサーバでかつポート22番が開いている事が前提です。windowsですとTera Termでサーバにログインし下記のコマンドを入力します。

mysql -u ユーザー名 -D データベース名 -p
//エンター後、Passwordの入力を行ってください。
次にMYSQLに切り替わったら、下記のコマンド入力してインポートを行います。この時の注意点ですがエラーなどが出る場合はエクスポートしたsqlファイルの最終行あたりに記入されているデータベース名やユーザー名が移行する側の名前になっているかが大事になります。なっていない場合、修正をかけ再処理を行うとインポートが行えるはずです。
尚、サーバ上に事前にsqlファイルをアップロードして置いてから処理を行ってください。
USE データベース名(インポートしたい)
SOURCE 階層を含むファイル名(/xxxx/xxxx.sql)

            	

著者名  @taoka_toshiaki

※この記事は著者が30代前半に書いたものです.

Profile
高知県在住の@taoka_toshiakiです、記事を読んで頂きありがとうございます.
数十年前から息を吸うように日々記事を書いてます.たまに休んだりする日もありますがほぼ毎日投稿を心掛けています😅.
SNSも使っています、フォロー、いいね、シェア宜しくお願い致します🙇.
SNS::@taoka_toshiaki

タグ

22, FTP, Linux, My, SCP, SQL, Tera, Term, Windows, WinSCP, アップロード, インストール, インポート, こちら, こと, コマンド, サーバ, サービス, ソフト, ダウンロード, データ, ファイル, フリー, プロトコル, ポート, メモ, もう一つ, ログイン, 一括, 下記, , , 入力, 前提, 可能, 名前, 大量, , 昨日, 機能, , 環境, 自分, 解決, 転送, 通り, 重宝,