![](/img/trans.png)
[英]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.