FtpAccess

FtpAccess

AtlasX.Engine.RemoteDirectory
class สำหรับเข้าถึงและจัดการไฟล์บน FTP server ผ่าน FluentFTP (Async)

Namespace: AtlasX.Engine.RemoteDirectory
Implements: IFtpAccess

Constructors

FtpAccess(String, String, String, String, Int32)

ParameterTypeRequiredDescription
hoststringRequiredชื่อ host หรือ IP ของ FTP server
rootPathstringRequiredPath หลักของ directory บน FTP server
usernamestringOptionalชื่อผู้ใช้สำหรับ login ค่าเริ่มต้นคือ anonymous
passwordstringOptionalรหัสผ่านสำหรับ login ค่าเริ่มต้นคือ string ว่าง
portintOptionalPort ของ FTP server ค่าเริ่มต้นคือ port21

Properties

NameTypeDescription
RootPathstringPath หลักของ directory บน FTP server
PathNamestringSub-path ที่ต่อจาก RootPath
DestinationPathstringPath เต็มที่ใช้งานจริง ได้จากการรวม RootPath และ PathName

Methods

NameReturnDescription
FileExistsAsync(String, CancellationToken)boolตรวจสอบว่าไฟล์มีอยู่บน FTP server หรือไม่
SaveFileAsync(String, Byte[], CancellationToken)voidอัปโหลดไฟล์ไปยัง FTP server
GetFileAsync(String, CancellationToken)Streamดาวน์โหลดไฟล์จาก FTP server และคืนเป็น Stream
RemoveFileAsync(String, CancellationToken)voidลบไฟล์ออกจาก FTP server
DirectoryExistsAsync(String, CancellationToken)boolตรวจสอบการมีอยู่ของ directory บน FTP server
CreateDirectoryAsync(String, CancellationToken)voidสร้าง directory บน FTP server
RemoveDirectoryAsync(String, CancellationToken)voidลบ directory ออกจาก FTP server
GetHashFromPathAsync(String, HashAlgorithmType, CancellationToken)stringคำนวณ hash ของไฟล์จาก path บน FTP server
GetHashFromStreamAsync(Stream, HashAlgorithmType, CancellationToken)stringคำนวณ hash ของไฟล์จาก Stream
FileExtension(String, Boolean)stringคืนค่านามสกุลไฟล์
DisposeAsync()voidตัดการเชื่อมต่อ FTP และคืน resources ทั้งหมด

Methods Details

FileExistsAsync(String, CancellationToken)

ตรวจสอบว่าไฟล์มีอยู่บน FTP server หรือไม่

Returns: booltrue ถ้าไฟล์มีอยู่

ParameterTypeRequiredDescription
fileNamestringRequiredชื่อไฟล์ที่ต้องการตรวจสอบ
cancellationTokenCancellationTokenOptionalToken สำหรับยกเลิก operation

SaveFileAsync(String, Byte[], CancellationToken)

อัปโหลดไฟล์ไปยัง DestinationPath บน FTP server โดยสร้าง directory อัตโนมัติถ้ายังไม่มี หรือหากมีไฟล์อยู่แล้วจะถูก overwrite

ParameterTypeRequiredDescription
fileNamestringRequiredชื่อไฟล์ที่ต้องการบันทึก
filebyte[]Requiredข้อมูลไฟล์ในรูปแบบ byte array
cancellationTokenCancellationTokenOptionalToken สำหรับยกเลิก operation

GetFileAsync(String, CancellationToken)

ดาวน์โหลดไฟล์จาก FTP server และคืนเป็น Stream

Returns: Stream– stream ของไฟล์ที่ดาวน์โหลด

ParameterTypeRequiredDescription
fileNamestringRequiredชื่อไฟล์ที่ต้องการดาวน์โหลด
cancellationTokenCancellationTokenOptionalToken สำหรับยกเลิก operation

RemoveFileAsync(String, CancellationToken)

ลบไฟล์ออกจาก FTP server
ถ้าไฟล์ไม่มีอยู่จะ skip โดยไม่เกิด exception

ParameterTypeRequiredDescription
fileNamestringRequiredชื่อไฟล์ที่ต้องการลบ
cancellationTokenCancellationTokenOptionalToken สำหรับยกเลิก operation

FileExtension(String, Boolean)

คืนค่านามสกุลของไฟล์

ParameterTypeRequiredDescription
fileNamestringRequiredชื่อไฟล์
excludeDotboolOptionalถ้าเป็น true จะตัด . นำหน้าออก เช่น .pdf > pdf

DirectoryExistsAsync(String, CancellationToken)

ตรวจสอบการมีอยู่ของ directory บน FTP server
Returns: booltrue ถ้า directory มีอยู่

ParameterTypeRequiredDescription
directoryNamestring?Optionalชื่อ sub-directory ถ้าไม่ระบุจะตรวจสอบที่ DestinationPath
cancellationTokenCancellationTokenOptionalToken สำหรับยกเลิก operation

CreateDirectoryAsync(String, CancellationToken)

สร้าง directory บน FTP server

ParameterTypeRequiredDescription
directoryNamestring?Optionalชื่อ sub-directory ถ้าไม่ระบุจะสร้างที่ DestinationPath
cancellationTokenCancellationTokenOptionalToken สำหรับยกเลิก operation

RemoveDirectoryAsync(String, CancellationToken)

ลบ directory และ contents ทั้งหมดภายในออกจาก FTP server

ParameterTypeRequiredDescription
directoryNamestring?Optionalชื่อ sub-directory ถ้าไม่ระบุจะลบที่ DestinationPath
cancellationTokenCancellationTokenOptionalToken สำหรับยกเลิก operation

GetHashFromPathAsync(String, HashAlgorithmType, CancellationToken)

คำนวณ hash ของไฟล์จาก path บน FTP server
Returns: string– hash string ในรูปแบบ uppercase hex

ParameterTypeRequiredDescription
filePathstringRequiredPath ของไฟล์ที่ต้องการคำนวณ hash (อิงจาก DestinationPath)
algorithmTypeHashAlgorithmTypeOptionalAlgorithm ที่ใช้คำนวณ hash ค่าเริ่มต้นคือ SHA256
cancellationTokenCancellationTokenOptionalToken สำหรับยกเลิก operation

GetHashFromStreamAsync(Stream, HashAlgorithmType, CancellationToken)

คำนวณ hash ของไฟล์จาก Stream
Returns: string– hash string ในรูปแบบ uppercase hex
Remarks: Stream ต้องรองรับ seek (CanSeek = true) เช่น MemoryStreamFileStream ถ้าเป็น NetworkStream หรือ GZipStream จะเกิด InvalidOperationException

ParameterTypeRequiredDescription
streamStreamRequiredStream ของไฟล์ที่ต้องการคำนวณ hash ต้องรองรับ seek
algorithmTypeHashAlgorithmTypeOptionalAlgorithm ที่ใช้คำนวณ hash ค่าเริ่มต้นคือ SHA256
cancellationTokenCancellationTokenOptionalToken สำหรับยกเลิก operation

DisposeAsync()

ตัดการเชื่อมต่อ FTP และคืน resources ทั้งหมด