 |
|
การดึง file จาก ftp server โดยดปิดเว็บ จาก client แล้วไม่สามารถ ดึงไฟล์ มาได้ |
|
 |
|
|
 |
 |
|
ปกติการอ้างอิงไฟล์บนเครื่องที่ผ่าน ASP จะเรียกได้เฉพาะใน Root ของ Web Server ครับ เช่น C:\Inetpub\wwwroot
|
 |
 |
 |
 |
Date :
2014-06-18 09:31:05 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือ ยัง งงๆ อยู่ครับ code ข้างบน จะทำหน้าที่ get file จาก ftp server : ซึ่งใช้คำสั่ง
objFTP.bQGetFile("/a.pdf","C:\Users\win7\Desktop\test\a.pdf",0,0,1,0)
ซึ่ง ผมใช้ คอมพิวเตอร์ เครื่อง A เป็น ASP server และ ftp server ด้วย
ผมเข้าเว็บ จาก เครื่อง B ซึ่ง "/a.pdf" คือ path ของ ftp ที่ได้แชร์ ไว้ บนเครื่อง A
ส่วน "C:\Users\win7\Desktop\test\a.pdf" คือ path ของเคื่อง B ที่ผมจะ get file จาก server มาไว้ที่ path นี้
แต่มันไม่สามารถ get file มาได้ครับ
แต่ถ้าผมเปลี่ยน "C:\Users\win7\Desktop\test\a.pdf" มาเป็น path ที่อยู่บนเครื่อง A มัน get มาได้ครับ
|
ประวัติการแก้ไข 2014-06-18 09:48:49
 |
 |
 |
 |
Date :
2014-06-18 09:46:56 |
By :
wittawatsuwannarak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าทำงานผ่าน Web browser ต้องส่งข้อมูลจากเครื่อง A ในลักษณะการ download file ครับ
ไม่จำเป็นต้องเขียนในลักษณะ ของ FTP
ในกรณีที่ต้องเขียนในลักษณะ FTP หมายถึง เครื่อง B ร้องขอข้อมูลจาก เครื่อง A
แต่เครื่อง A ไม่มีข้อมูลอยู่ บนเครื่อง A ต้อง FTP ไปเอาข้อมูลบนเครื่อง C
เราถึงจะต้องเขียนโปรแกรมผ่านขบวนการ FTP ให้กับ Server A ครับ
ไม่ทราบว่าจะถูกต้องกับความต้องการไหมครับ
|
 |
 |
 |
 |
Date :
2014-06-18 20:17:35 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือ ผมทำ web server กับ ftp server ไว้เครื่องเดียวกันอยู่ครับ ซึ่งก็คือ เครื่อง A
|
ประวัติการแก้ไข 2014-06-19 08:28:26
 |
 |
 |
 |
Date :
2014-06-19 08:28:05 |
By :
wittawatsuwannarak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าเรียกจาก เครื่อง B ผ่าน web browser โดยใช้ protocol HTTP และต้องการ เก็บ file ไว้ในเครื่อง B ด้วย
ถึงแม้เครื่อง A จะมี FTP Server ตัวโปรแกรมก็ไม่จำเป็นต้องใช้ function FTP ครับ
ใช้แค่ คำสัง อ่านไฟล์ และ กำหนดส่วนหัวก่อนที่จะ Response data ออกไป
แต่ถ้าอยากใช้ feature FTP
เมื่อ get file มาไว้ที่ "C:\Users\win7\Desktop\test\a.pdf" บนเครื่อง A แล้ว
ก็ให้ทำการ อ่านไฟล์ นั้นแล้ว ค่อย response data ออก ไป เหมือนกันกับข้างบน
โดยกำหนดส่วนหัว ตามนี้ครับ
Code (ASP)
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "text/plain";
Response.AddHeader("content-disposition", "attachment; filename=" + filename);
Response.Write(data);
Response.Flush();
Response.Close();
ปล.แก้ไข เพราะ มั่วระหว่าง code php กับ asp (ตอบมากๆ ชักเมา 5555)
|
ประวัติการแก้ไข 2014-06-19 11:53:10 2014-06-19 11:58:26
 |
 |
 |
 |
Date :
2014-06-19 10:23:07 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ ผมใช้โค้ด ในการโหลด จาก web server
Code (ASP)
<%@Language="VBScript"%>
<%Option Explicit%>
<%Response.Buffer = True%>
<%
On Error Resume Next
Dim strPath
strPath = "test.exe"
'-- do some basic error checking for the QueryString
If strPath = "" Then
Response.Clear
Response.Write("No file specified.")
Response.End
ElseIf InStr(strPath, "..") > 0 Then
Response.Clear
Response.Write("Illegal folder location.")
Response.End
ElseIf Len(strPath) > 1024 Then
Response.Clear
Response.Write("Folder path too long.")
Response.End
Else
Call DownloadFile(strPath)
End If
Private Sub DownloadFile(file)
'--declare variables
Dim strAbsFile
Dim strFileExtension
Dim objFSO
Dim objFile
Dim objStream
'-- set absolute file location
strAbsFile = Server.MapPath(file)
'-- create FSO object to check if file exists and get properties
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'-- check to see if the file exists
If objFSO.FileExists(strAbsFile) Then
Set objFile = objFSO.GetFile(strAbsFile)
'-- first clear the response, and then set the appropriate headers
Response.Clear
'-- the filename you give it will be the one that is shown
' to the users by default when they save
Response.AddHeader "Content-Disposition", "attachment; filename=" & objFile.Name
Response.AddHeader "Content-Length", objFile.Size
Response.ContentType = "application/octet-stream"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
'-- set as binary
objStream.Type = 1
Response.CharSet = "UTF-8"
'-- load into the stream the file
objStream.LoadFromFile(strAbsFile)
'-- send the stream in the response
Response.BinaryWrite(objStream.Read)
objStream.Close
Set objStream = Nothing
Set objFile = Nothing
Else 'objFSO.FileExists(strAbsFile)
Response.Clear
Response.Write("No such file exists.")
End If
Set objFSO = Nothing
End Sub
%>
แต่บังเอิญ ไฟล์ ที่จะ โหลด มันเป็น .exe ซึ่ง มันไม่สามารถ โหลดได้ ครับ แต่ถ้าเป็น พวก file .txt อะไรพวกนี้ มันสามารถ โหลด
มันต้องไป เพิ่ม buffer อะไรหรือป่าวครับ
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2014-06-19 15:59:52 |
By :
wittawatsuwannarak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้ ผมไม่แน่ใจนะครับว่าจะทำได้ ไหม แต่ บน php ผม transfer exe ได้ครับ
คงต้องหาเปรียบเที่ยบเอานะครับ ผมไม่ได้ลง Asp ไว้บนเครื่อง
header("Content-Type: application/force-download\n");
header("Content-Transfer-Encoding: binary\n");
อาจต้องรอผู้ชำนาญ ASP มาตอบแล้วครับ
|
 |
 |
 |
 |
Date :
2014-06-19 18:42:11 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|