[英]Need to move and handle file from one server with C# to anoter server with php?
I have two websites online ie 1st is PM which is developed using asp.net, C# ,sql server and 2nd one is developed using php ,mysql. 我有两个在线网站,第一个是使用asp.net,C#,sql server开发的PM,第二个使用php,mysql开发。
I need to manage data by choosing one website for CRUD operations (asp.net) and on another website(php) the viewer can only view data (nserted by asp.net website). 我需要通过选择一个网站进行CRUD操作来管理数据(asp.net),而在另一个网站(php)上,查看者只能查看数据(由asp.net网站插入)。
as the information viewed is same but on different websites. 因为查看的信息是相同的,但是在不同的网站上。
I need to insert persons data with 3 sample files on asp .net website and insert and move info + samples fies to the php website . 我需要在asp .net网站上插入带有3个示例文件的人员数据,并将信息和示例文件插入并移动到php网站。
I really dont have any idea to achieve that ,I can use Webclient() to post data to php web but still how can i move files to the php page . 我真的没有任何想法要实现这一点,我可以使用Webclient()将数据发布到php网站,但仍然如何将文件移动到php页面。
Can i pass file path from c# to PHP using webclient /ajax post to upload file from one server to another ? 我可以使用webclient / ajax post将文件路径从c#传递到PHP,以将文件从一台服务器上传到另一台服务器吗?
comment posted said ! 发表评论说!
"a file input is for sending files from your computer to the server. PHP cannot "reach out" to your local computer and grab a file, even if you pass it the full path. This is NOT possible as it would be a massively HUGE security hole." “文件输入是用于将文件从您的计算机发送到服务器。PHP无法“延伸”到本地计算机并获取文件,即使您通过了完整路径也是如此。这是不可能的,因为这将是巨大的安全孔。”
Passing file path to php script 将文件路径传递到php脚本
Need help :( 需要帮忙 :(
kindly repli 亲切的答复
You can install and set up ftp software on the php server, and then you can use FtpWebRequest in c# to upload the file: 您可以在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.