こんにちは、私は c# と Sharpssh の初心者です。csv ファイルを sqlite3 データベースにエクスポートし、explor という外部デバイスにエクスポートしようとしています。csvファイルをローカルのsqlite3データベースにエクスポートし、sharpsshを使用して外部デバイスにデータベースに接続できましたが、両方を同時に行いたいです。1) 外部デバイスに接続します 2) csv ファイルをデバイスのデータベース/テーブルにエクスポートします。 どんな助けでも大歓迎です。
1.SHARPSSHによる接続
string _ftpURL = @"192.178.0.77"; //(FAKE IP)
string _UserName = "root"; //FAKE User Name of the SFTP server
string _Password = "preethi"; //FAKE Password of the SFTP server
int _Port = 2222; //Port No of the SFTP server (if any)
string _ftpDirectory = "/home/root/systools/WM/WebMobility.db"; //The directory in SFTP server where the files will be uploaded
string LocalDirectory = "I:\\preethi"; //Local directory from where the files will be uploaded
string FileName = "exploretest.csv"; //File name, which one will be uploaded
// IPHostEntry ip = Dns.GetHostEntry(@"1.1.1.2");
Sftp Connection = new Sftp(_ftpURL,_UserName, _Password);
Connection.Connect(_Port);
CSV ファイルのエクスポート
string strFileName = "I:/preethi/exploretest.csv";
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + System.IO.Path.GetDirectoryName(strFileName) + "; Extended Properties = \"Text;HDR=YES;FMT=Delimited\"");
conn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM " + System.IO.Path.GetFileName(strFileName), conn);
DataSet ds = new DataSet("Temp");
adapter.Fill(ds);
DataTable tb = ds.Tables[0];
//SQLiteConnection.CreateFile("MyDatabase.sqlite");
SQLiteConnection m_dbConnection;
m_dbConnection = new SQLiteConnection("Data source = 19.9.9.3; port=2222; database = WebMobility.db; uid=root; pwd=preethi; Convert Zero Datetime=true;");
m_dbConnection.Open();
var dt = ds.Tables[0];
foreach (DataRow dr in dt.Rows)
{
var Id = dr["Id"].ToString();
var VRM = dr["VehicleRegistration"].ToString();
var Points = Convert.ToInt32(dr["TicketScore"].ToString());
string sql = "insert into NaughtyList (Id,VRM,Points) values ( '" + Id + "','" + VRM + "'," + Points + ")";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
}
m_dbConnection.Close();