[英]How to move a file from one folder to another folder on a remote server using SharpSsh and C#
[英]Need to move and handle file from one server with C# to anoter server with php?
我有兩個在線網站,第一個是使用asp.net,C#,sql server開發的PM,第二個使用php,mysql開發。
我需要通過選擇一個網站進行CRUD操作來管理數據(asp.net),而在另一個網站(php)上,查看者只能查看數據(由asp.net網站插入)。
因為查看的信息是相同的,但是在不同的網站上。
我需要在asp .net網站上插入帶有3個示例文件的人員數據,並將信息和示例文件插入並移動到php網站。
我真的沒有任何想法要實現這一點,我可以使用Webclient()將數據發布到php網站,但仍然如何將文件移動到php頁面。
我可以使用webclient / ajax post將文件路徑從c#傳遞到PHP,以將文件從一台服務器上傳到另一台服務器嗎?
發表評論說!
“文件輸入是用於將文件從您的計算機發送到服務器。PHP無法“延伸”到本地計算機並獲取文件,即使您通過了完整路徑也是如此。這是不可能的,因為這將是巨大的安全孔。”
需要幫忙 :(
親切的答復
您可以在php服務器上安裝並設置ftp軟件,然后可以在c#中使用FtpWebRequest上傳文件:
private FtpWebRequest GetRequest(string requestUri, string method, bool keepAlive)
{
FtpWebRequest retVal = null;
try
{
retVal = FtpWebRequest.Create(requestUri) as FtpWebRequest;
retVal.Method = method;
retVal.Credentials = new NetworkCredential(username, password);
retVal.UsePassive = true;
retVal.UseBinary = true;
retVal.KeepAlive = keepAlive;
// retVal = request.GetRequestStream();
}
catch (Exception ex)
{
}
return retVal;
}
public bool UploadFile(string fileToUpload)
{
bool retVal = false;
FtpWebRequest request = null;
Stream outstream = null;
FileStream fs = null;
try
{
request = GetRequest(String.Format("{0}/{1}", host, Path.GetFileName(fileToUpload)), WebRequestMethods.Ftp.UploadFile, false);
byte[] buffer = new byte[4096];
int count = 0;
outstream = request.GetRequestStream();
using (FileStream streamReader = File.OpenRead(fileToUpload))
{
int read;
while ((read = streamReader.Read(buffer, 0, buffer.Length)) > 0)
{
Console.WriteLine("Writing to FTP stream: " + (count += read));
outstream.Write(buffer, 0, read);
outstream.Flush();
}
}
retVal = true;
}
catch (Exception ex)
{
}
finally
{
Console.WriteLine("Closing the FTP stream");
if (request != null)
{
request.Abort();
}
if (outstream != null)
outstream.Close();
}
return retVal;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.