在WEB可以用FtpWebRequest這個元件上傳檔案
作法如下
[VB.net]
作法如下
[VB.net]
Imports System.Web
Imports System.Net
Imports System.IO
Dim ftpRequest As FtpWebRequest = CType(WebRequest.Create("ftp://ftpServerName/folder/" & fileName), FtpWebRequest) '先產生遠端檔案
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile
ftpRequest.Proxy = Nothing
ftpRequest.UseBinary = True
ftpRequest.Credentials = New NetworkCredential("User", "Password")
Dim ff As New FileInfo(localPath & fileName)
Dim fileStream As FileStream = File.Open(localPath & fileName, FileMode.Open)'讀取檔案
Dim bytes() As Byte = New Byte(ff.Length) {}
fileStream.Read(bytes, 0, ff.Length)
Dim streamWriter As Stream = ftpRequest.GetRequestStream()
streamWriter.Write(bytes, 0, bytes.Length)'遠端寫入
streamWriter.Close()
留言