如何在远程服务器上上传文件? [英] How do I upload a file on remote server?

查看:112
本文介绍了如何在远程服务器上上传文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何将文件网址上传到远程服务器中的文件夹

How I upload a file url to my folder which is in remote server

推荐答案

File.copy(src, dest);



//用这个来将文件从一个点复制到另一个点



//如果你愿意的话复制到另一台服务器然后使用ftp








//use this to copy file from one point to another

// if u would like copy onto another server then use ftp



public void ftpfile(string ftpfilepath, string inputfilepath)  
{  
    string ftphost = "127.0.0.1";  
    //here correct hostname or IP of the ftp server to be given  

    string ftpfullpath = "ftp://" + ftphost + ftpfilepath;  
    FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);  
    ftp.Credentials = new NetworkCredential("userid", "password");  
    //userid and password for the ftp server to given  

    ftp.KeepAlive = true;  
    ftp.UseBinary = true;  
    ftp.Method = WebRequestMethods.Ftp.UploadFile;  
    FileStream fs = File.OpenRead(inputfilepath);  
    byte[] buffer = new byte[fs.Length];  
    fs.Read(buffer, 0, buffer.Length);  
    fs.Close();  
    Stream ftpstream = ftp.GetRequestStream();  
    ftpstream.Write(buffer, 0, buffer.Length);  
    ftpstream.Close();  
}


这篇关于如何在远程服务器上上传文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆