 |
|
รบกวนขอวิธีการทำ SFTP รับส่งไฟล์หน่อยครับผ่านแอปที่เราสร้างหน่อยครับ |
|
 |
|
|
 |
 |
|
ผ่านแอพที่ว่านี่ คือวินโดว์แอพใช่มั๊ย
------------------------------------------
I) เขียนทั้งสองฝั่ง ทั้งฝั่ง Server และฝั่ง Client
- เขียนวินโดว์แอพฝั่ง Server รอรับไฟล์ผ่าน protocol SFTP(port 22 listening)
- เขียนวินโดว์แอพฝั่ง Client เพื่อส่งไฟล์ผ่าน protocol SFTP
II) เขียนวินโดว์แอพฝั่ง Client ส่งไฟล์ผ่าน SFTP
- มีโปรโปรแกรม SFTP Server(port 22 listening) อยู่แล้ว
- เขียนวินโดว์แอพให้ส่งไฟล์ผ่าน SFTP Client Protocol
<<<<ฝั่ง Client>>>>>
- ลองดูที่นี่ https://www.codeproject.com/Tips/1111060/Upload-File-to-SFTP-Site-with-Csharp-in-Visual-Stu
- โหลด SSH.NET จาก NuGet Packages ชื่อ SSH.Net --> Install Latest Stable Version
- new class in project
Code (C#)
using Renci.SshNet;
using System.IO;
namespace YourProjectNamespace
{
class sftp
{
public static void UploadSFTPFile(string host, string username,
string password, string sourcefile, string destinationpath, int port)
{
using (SftpClient client = new SftpClient(host, port, username, password))
{
client.Connect();
client.ChangeDirectory(destinationpath);
using (FileStream fs = new FileStream(sourcefile, FileMode.Open))
{
client.BufferSize = 4 * 1024;
client.UploadFile(fs, Path.GetFileName(sourcefile));
}
}
}
}
}
- เรียกใช้ sftp class จาก form
Code (C#)
using System;
using System.IO;
using sftp;
string source = @"FilePath and FileName of Local File to Upload";
string destination = @"SFTP Server File Destination Folder";
string host = "SFTP Host";
string username = "User Name";
string password = "password";
int port = 22; //Port 22 is defaulted for SFTP upload
sftp.UploadSFTPFile(host, username, password, source, destination, port);
<<<<<ฝั่ง Server>>>>>
-ใช้ software สำเร็จรูปดีกว่า https://www.pcwdld.com/10-best-free-sftp-servers
- generate private key and load on server(for encrypt)
- start SFTP server
|
ประวัติการแก้ไข 2017-08-15 17:34:30
 |
 |
 |
 |
Date :
2017-08-15 17:33:39 |
By :
ccjpn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เดวจาลองทำดูครับ
ขอบคุณมากๆ ครับ
|
 |
 |
 |
 |
Date :
2017-08-16 10:25:23 |
By :
darkgolfman0 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|